[英]Access parent's DOM from script in an iframe in IE Mobile
我有一個帶框的 window(目前是 iframe,但可能是框架) - 我無法控制這個。
我想檢測我的內容是否在 iframe(或框架)內。
我想將當前文檔的位置與頂部的 object 進行比較,但它似乎是相同的 object(頂部 === 窗口)。
經過廣泛的谷歌搜索后,我找到了這個IEMobile 博客條目,在其中一個評論中有這個答案:
iemoblog 說:
不,您不能從 IE Mobile 中 iframe 中的腳本訪問父 DOM 的任何部分。
2007 年 12 月 20 日下午 12:12
我似乎找不到任何關於此的文檔 - 任何人都可以幫助確認這一點甚至更好 - 建議一種方法來檢測頁面是否“框架”?
由於在IE Mobile 博客中找到評論后我沒有得到任何結果(Charles Morris - IE Mobile 團隊的項目經理,在他自己的帖子中)我不得不添加這個答案和 state 它是:
按照設計(或至少是一個錯誤)
prc 說:
關於 iframe 支持:我可以創建 iframe,但無法“向外看”框架。 “top”和“parent”似乎都只指 iframe 本身,而不是文檔建議的最頂層祖先或直接祖先。 有沒有辦法從 iframe 中引用隨附文檔中的 javascript 變量?
2007 年 12 月 19 日晚上 9:29
iemoblog 說:
不,您不能從 IE Mobile 中 iframe 中的腳本訪問父 DOM 的任何部分。
2007 年 12 月 20 日下午 12:12
主要問題是,如果框架來自與容器不同的域,那么您的 JavaScript 被沙盒化,無法訪問其他框架/容器。
What you can do is try to compare window
to window.top
and the possible outcomes are: 1. The are the same -> you are the top window on the page 2. They are not the same -> you are not the top window在頁面上,有一些容器頁面,與您在同一個域中,將您的 window 保存為框架或 iframe。 3. 拋出安全異常->你不是頁面頂部的window,但頂部的window來自另一個域,你不能訪問它。
也許是這樣的:
try {
if (window == window.top)
return "I'm parent";
else
return "I'm a child of " + window.top.location;
} catch (e) {
return "I'm a child of something from another domain";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.