首頁  >  文章  >  web前端  >  JS廣告跳轉

JS廣告跳轉

巴扎黑
巴扎黑原創
2016-12-10 09:07:431676瀏覽

在網路上看到的一段廣告程式碼

Js程式碼  

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

 

上述程式碼在webkit核心瀏覽器下新建一個隱藏的iframe做跳轉,在IE下透過refresh跳轉,涉及到的知識點挺多的。

 

瀏覽器判斷

/webkit/i.test()此語法比較有奇怪,判斷UA是否有webkit關鍵字。

 

Js程式碼  

if( /webkit/i.test(navigator.userAgent) )// webkit核心  

else if( /msie/i .test(navigator.userAgent) )  // ie  

{  

alert('ie');  

}  

Js代碼  

function show()  

{  

    return print();  

  

    function print );

    }  

}  

 

跳轉屬性

window.location.href 、location.href 是本頁跳轉

parent.location.href 是上一層頁跳轉

top.location.href 是最外層的頁跳到

 

refresh屬性值

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

指定頁面meta屬性為refresh也可實現頁面跳轉,content指定N秒鐘後實現跳躍。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn