`
tcspecial
  • 浏览: 898938 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

JS广告跳转

    博客分类:
  • web
阅读更多

 

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

/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 是上一层页面跳转

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

 

refresh属性值

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

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

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics