js實(shí)現(xiàn)防止被iframe的方法
更新時間:2015年07月03日 15:35:25 作者:不吃皮蛋
這篇文章主要介紹了js實(shí)現(xiàn)防止被iframe的方法,實(shí)例分析了兩種比較常用的javascript防止頁面被iframe的技巧,非常簡單實(shí)用,需要的朋友可以參考下
本文實(shí)例講述了js實(shí)現(xiàn)防止被iframe的方法。分享給大家供大家參考。具體如下:
方法一:
<script>
// Break out of an iframe, if someone shoves your site
// into one of those silly top-bar URL shortener things.
//
// Passing `this` and re-aliasing as `window` ensures
// that the window object hasn't been overwritten.
//
// Example:
// var window = 'haha, punked!';
//
// Note: Probably unnecessary, but just for kicks.
(function(window) {
if (window.location !== window.top.location) {
window.top.location = window.location;
}
})(this);
</script>
方法二:
<script> // A more cryptic one-liner, to awe & impress. // // No need to protect `window` since `this` is // immutable, and at the topmost level means // `window` anyways. Here, we compare locations // on the left side of the "&&" and execute the // code in parenthesis if that condition is // true (top location isn't iframe location). // // Otherwise, nothing happens. It's basically an // if statement without wrapping curly brackets. // // Weird, I know. But pretty cool, right? :) this.top.location !== this.location && (this.top.location = this.location); </script>
希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
利用JavaScript實(shí)現(xiàn)簡單3D開關(guān)書本模型
這篇文章主要為大家詳細(xì)介紹了如何利用JavaScript實(shí)現(xiàn)簡單3D開關(guān)書本模型的效果,文中的實(shí)現(xiàn)代碼講解的非常詳細(xì),具有一定參考價值,感興趣的同學(xué)可以動手嘗試一下2023-11-11
JS實(shí)現(xiàn)選擇TextArea內(nèi)文本的方法
這篇文章主要介紹了JS實(shí)現(xiàn)選擇TextArea內(nèi)文本的方法,涉及javascript針對頁面TextArea元素焦點(diǎn)設(shè)置及文本獲取的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08
JavaScript 數(shù)組去重并統(tǒng)計(jì)重復(fù)元素出現(xiàn)的次數(shù)實(shí)例
下面小編就為大家分享一篇JavaScript 數(shù)組去重并統(tǒng)計(jì)重復(fù)元素出現(xiàn)的次數(shù)實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
純javascript實(shí)現(xiàn)簡單下拉刷新功能
這篇文章主要介紹了純javascript實(shí)現(xiàn)簡單下拉刷新功能,沒有借助任何的框架,十分簡單實(shí)用,有需要的小伙伴來參考下吧。2015-03-03
JS 設(shè)計(jì)模式之:工廠模式定義與實(shí)現(xiàn)方法淺析
這篇文章主要介紹了JS 設(shè)計(jì)模式之:工廠模式,結(jié)合實(shí)例形式分析了JS 工廠模式基本概念、原理、定義、實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05

