2011-08-24 36 views
1

我一直試圖通過兩個來自另一個域的頁面中加載的相同域的 iframe進行通信。防止瀏覽器在iframe的文檔中加載自定義框架集

問題是瀏覽器在iframe的內容上創建了一個定製的框架集。 我無法從iframe中使用parent.iframes [x] .name檢索iframe名稱,因爲腳本地址爲框架集作爲父級。

下面是我實際的HTML代碼 -

<html> 
<head> 
</head> 
<body> 
    <p>iframe1</p> 
    <script type="text/javascript"> 
    var frames = parent.frames; 
    for(var i=0; i < frames.length; i++) 
    { 
    if(frames[i].name != "undefined") 
     alert(frames[i].name); 
    } 
    </script>  
</body> 
</html> 

下面是什麼瀏覽器生成 -

<!--inside iframe--> 
<html> 
    <head></head> 
    <frameset border="0" rows="100%,*" cols="100%" frameborder="no"> 
     <!--actual document goes inside frame tag--> 
     <frame name="TopFrame" scrolling="yes" noresize="" src="http://abnormalz.stuffshake.com/fframe.html"> 
    <frame name="BottomFrame" scrolling="no" noresize=""> 
    <noframes></noframes> 
    </frameset> 
</html> 

有沒有辦法解決這個問題?

您可以在http://stuffshake.com/parent.html

回答

1

檢查測試只需使用的localStorage或sessionStorage的。由於兩個iframe都來自同一個域,因此它們共享相同的localStorage。如果修改了值,LocalStorage會發送事件。

自IE8起支持。

+0

感謝這有助於,但我不明白爲什麼瀏覽器是通過iframes創建自定義框架集。 –