2011-05-03 83 views

回答

0

您可以使用window.parent.location來獲取iframe中的父URL並相應地執行操作。如果未定義window.parent,則可能意味着直接調用了iframe.html。如果已定義,請檢查該值並確保它來自您的域上的/index.html。

+0

@s imshaun,@Darin Dimitrov,'window.parent.location'只是將'iframe.html'重定向到'index.html',但我需要一些效果,比如'bing shopping' – 2011-05-03 21:48:41

+0

@yuli chika,'window.parent.location' doesn不會重定向到任何地方:它會爲您提供父託管頁面的位置(如果有)。如果您修改該值,則會重定向。但在這裏我們正在討論閱讀它,並根據其價值作出相應的行動。順便說一句,這是'iframe.html'知道父容器的唯一方法。 – 2011-05-03 21:50:52

0

我想這應該這樣做...

var inIframe = window.location != window.parent.location; 
0

您可以在Iframe.html的使用此javascript:

if (top.location.href != 'http://www.site.com/index.html') { 
    // the proper redirect here 
    top.location.href = 'http://www.site.com/index.html'; 
} 

這種方式,將永遠被載入爲I幀

+0

Diallo,儘量使用你給的東西,但是當打開'index.html'時,實際上當你打開index.html的時候頁面總會刷新 – 2011-05-03 21:36:58

+0

它不應該刷新,如果頁面不同,條件只是'true' 。此代碼進入iframe.html頁面而不是index.html – Ibu 2011-05-03 22:02:12

2
if(self == top) 
location.href='/'; 

把這個在iframe頁面

相關問題