首页 > web前端 > js教程 > 正文

JS广告跳转

巴扎黑
发布: 2016-12-19 14:49:43
原创
1093人浏览过

在网上看到的一段广告代码

/webkit/i.test(navigator.userAgent) ? (f = d.createElement('iframe'), f.style.width = 1, f.style.height = 1, 
f.frameBorder = 0, d.body.appendChild(f).src = 'javascript:"<script>top.location.replace(\'' + u + '\')<\/script>"') : (d.open(), 
d.write(['<meta http-equiv="refresh"content="0;url=', '"/>'].join(u)), d.close());
登录后复制

上述代码在webkit内核浏览器下新建一个隐藏的iframe做跳转,在IE下通过refresh跳转,涉及到的知识点挺多的。

浏览器判断

/webkit/i.test()该语法比较有奇怪,判断UA是否有webkit关键字。

if( /webkit/i.test(navigator.userAgent) )// webkit内核
{
alert('webkit');
}
else if( /msie/i.test(navigator.userAgent) )  // ie
{
alert('ie');
}
登录后复制

 Javascript匿名函数还能这么玩

function show()
{
return print();
function print(){
console.log('print method');
}
}
登录后复制

跳转属性

window.location.href、location.href 是本页面跳转

parent.location.href 是上一层页面跳转

固定层侧边广告js代码
固定层侧边广告js代码

固定层侧边广告js代码

固定层侧边广告js代码 27
查看详情 固定层侧边广告js代码

top.location.href 是最外层的页面跳转

 

refresh属性值

<meta http-equiv="refresh"content="0;url='www.baidu.com'/>

指定页面meta属性为refresh也可实现页面跳转,content指定N秒钟后实现跳转。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号