判断手机或电脑让不同的iframe显示或隐藏

一,把pc_or_mobile.js 上传到源站的根目录中.
比如您打算存放js的站域名为 http://700.com/
则可以把js放在http://700.com/网站服务器的根目录中,当在其它网站上引入时,就可以这样写了
  <script src="http://700.com/pc_or_mobile.js"></script>

pc_or_mobile.js这个文件中的内容为


    if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) { 
//移动端
document.writeln("<div style=\'margin:0 auto;width:100%;text-align:center;;-position:relative;overflow:hidden\'><iframe src=\'https://www.sina.com/\'margin-top: 0px; position: relative;left:0; width=\'100%\'height=\'1800\' frameborder=\'0\' ></iframe></div>");

}else{
	document.writeln("<div style=\'margin:0 auto;text-align:center;position:relative;overflow:hidden\'><iframe scrolling=\'no\' src=\'https://www.baidu.com/\' width=\'1200'height=\'3700\' frameborder=\'0\' align=\'middle\' style=\'margin-top: -90px; position: relative;left:0;\'></iframe></div>");
	//上面margin-top: -90px;的作用是隐藏对方网站的logo,导航条等,不需要时,可以设置为0

}

二,假如js放在http://700.com/网站根目录中

a站要显示这个js中的内容,则增加js调用,
(电脑上,需要ctrl+f5 刷新,才可正常显示修改效果)

模板上直接添加以下代码:

  <script type="text/javascript" src="http://700.com/pc_or_mobile.js"></script>

 // 如果不希望手机上有缓存,方便刷新调试查看.可以这样调用

   <script>
    document.write('<script src="http://700.com/pc_or_mobile.js?adv='+Math.random()+'"><\/script>');
	</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值