返回列表 发布新帖
查看: 902|回复: 0

仿小刀网站广告位只在国外显示的js代码

捣蛋鬼魔神·索伦森

梦之瑶-飞哥发表于 2020-1-15 10:36:57 | 查看全部 |阅读模式

您需要登录账号才能看到图片及隐藏内容,马上注册享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
有的网站广告位 有时候我们想某些东西只在国内显示,国外不显示,或者只在国外显示国内不显示,想设置限定国外ip广告显示效果那么如何通过代码实现呢?

此代码大多数用于广告,想让广告国内不显示,只显示国外IP用户,可以直接使用下面代码。

声明:我不是作者,代码效果自己测试
JS判断文件:

  1. <div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);"><script></div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">function ip(o){</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">if (!/China/.test(o.country)) {</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">document.getElementsByClassName('index-ad-banner').item(0).style.display='block';</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">}</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">}</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">var s = document.createElement('script');</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">s.type = 'text/javascript';</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">s.src = 'http://ip-api.com/json/?callback=ip';</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">document.body.append(s);document.write('<style>.index-ad-banner{display:none;}</style>');</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);"></script></div>
复制代码


css样式代码:

  1. <div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);"><style>.index-ad-banner {width: 100%; height: auto;}</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">index-ad-banner li { float: left; width: 25%; box-sizing: border-box; border: 1px solid #000; line-height: 10px; text-align:center; padding: 10px; margin: 0px; }</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);"></style></div>
复制代码


最后是调用代码:

  1. <div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);"><div class="index-ad-banner"></div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);">这里放广告代码</div><div style="outline: 0px; zoom: 1; background-color: rgb(233, 233, 231);"></div></div>
复制代码




<
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

投诉/建议联系

xm520vip@gmail.com

未经授权禁止转载,复制和建立镜像,
如有违反,追究法律责任
  • 关注公众号
  • 关注小程序
Copyright © 2001-2025 灵歆论坛 版权所有 All Rights Reserved. |网站地图
关灯 在本版发帖
扫一扫进入小程序页面
QQ客服返回顶部
快速回复 返回顶部 返回列表