2012-04-03 150 views
0

我使用JavaScript來判斷一個網頁是在一個IFRAME:如何判斷頁面是否在iframe中使用javascript?

if (this != top) { 
    alert("true"); 
} 

enter image description here

,但我得到「真」的時候,即使不是在IFRAME(如電圖畫),誰也幫我?

+2

[可能感興趣的一個老問題。(http://stackoverflow.com/questions/958997) – Pointy 2012-04-03 15:19:36

+1

或可能[這](http://stackoverflow.com/questions/ 925039 /檢測的iframe嵌入合的JavaScript)。 – 2012-04-03 15:20:48

回答

4

嘗試

if (self != top) { 
    alert("true"); 
} 
相關問題