2011-07-04 18 views
1

所以我知道有很多網站試圖從框架(框架破壞),然後有這整個循環「破壞框架擊球手」和「破壞框架剋星」等等。有沒有辦法預測一個網站是否會試圖突破你的框架?我想讓我的程序嘗試將網站加載到一個框架中,如果它試圖突破,只需放棄嘗試並停止加載框架。這是我之前嘗試過的:如何停止加載網站,如果它試圖逃離一個框架

<iframe id="framed_source" src = "<%= @excerpt.url %>"></iframe> 
<script type="text/javascript"> 
    if (top === self) 
    { 
     $(".framed_source").remove(); 
    } 
</script> 

不幸的是,即使刪除了iframe,它仍然會重定向到原始網站?我怎樣才能刪除框架,並放棄嘗試加載他們的網站,所以沒有重定向發生?

+0

怎樣才能永遠===自我? – Val

+1

@Val如果當前窗口('self')是最外層窗口('top')。 – lonesomeday

回答

0

這裏有一個例子

<div id="pcontent"></div> <!-- Page 1 html --> 
<script> 
    setInterval(function(){//set interval 
     if(!$('iframe').contents().find('#icontent').length)//check if div exists on iframe 
      window.location.href= 'blbla.com';//if so redirect 
    },100);//end interval 
</script> 
<iframe> <!-- This is your iframe below is the javascript code should go to page2.html --> 
    <div id="icontent"></div> 
    <script> 
    setInterval(function(){ 
     if(!top.getElementById('pcontent').length)//check if the div exists on top most window 
     window.location.href= 'blbla.com'; 
    },100); 
    </script> 
</iframe> 

現在:裏面的iframe是什麼iframe中應該有... [圖僅]

你也可以檢查其他的東西一樣,如果內容不要」 t有寬度,高度,內部文本和html不匹配等...

+0

你能解釋這段代碼應該如何工作嗎?我遇到了一些麻煩 – Kvass

+0

我運行了這段代碼,它只是呈現一個空的iframe和一個空白頁面 - 我不明白它表示什麼或者它是如何回答我在跳幀前重定向的問題。 – Kvass

+0

iframe裏面的東西應該是你的url的地方......,我說它只適用於指引線,它是一個非常複雜的東西,它不能簡單地解釋... – Val

0

與此代碼用戶將被提示,如果他想要他可以保留在您的網頁中...(我還沒有嘗試它)

<script type="text/javascript"> 
    window.onbeforeunload=function(e){ 
     $(".framed_source").remove(); 
     return 'Please keep here I will remove that buster iframe!'; 
    } 
<script type="text/javascript"> 
相關問題