admin管理员组文章数量:1026968
We have a web application where we're using "top.document" since this application uses iframes and sometimes we must reach the top document.
The problem started now since we need to integrate this application in a website and we put it inside an iFrame in this very site. Since the application uses "top.document" it is reaching the site's "document" instead of the application's "top".
Do you have any ideas to help us solve the problem?
Thanks in advance!
Rui
We have a web application where we're using "top.document" since this application uses iframes and sometimes we must reach the top document.
The problem started now since we need to integrate this application in a website and we put it inside an iFrame in this very site. Since the application uses "top.document" it is reaching the site's "document" instead of the application's "top".
Do you have any ideas to help us solve the problem?
Thanks in advance!
Rui
Share Improve this question asked Nov 5, 2009 at 16:10 RuiRui 111 gold badge1 silver badge2 bronze badges3 Answers
Reset to default 1Assuming your iframe is one level deep:
parent.document
or, if it's deeper:
parent.parent.parent.parent.document
but I really hope it's not that deep ;-)
The approach to ensuring that you are looking at the correct window is to know where you are within the framed application.
For example, let us say the “main frame” is the root of the site. Within the main frame, additional ‘iFrames’ are defined. The pages that are loaded in these additional frames need to know where they are in the frame hierarchy.
So you see, understanding where you are in the hierarchy of frames and pop-ups will allow you to properly backtrack and define references to functions and objects contained within windows in previous pages/frames.
Adding some Javascript code to give you an idea:
if (window.self){
if (window.top == window) {
if (window.name == "main_frame"){
MainFrameRef = window.top;
return MainFrameRef;
} else {
return false;
}
}
}
If you are looking for dead simple, look for known ids, and that's where you stop your upward crawl of parents and tops and docs.
Or you could have each frame register itself in some global variable (namespaced of course) when they load, that way you have a reference to them and do not need to traverse the DOM.
We have a web application where we're using "top.document" since this application uses iframes and sometimes we must reach the top document.
The problem started now since we need to integrate this application in a website and we put it inside an iFrame in this very site. Since the application uses "top.document" it is reaching the site's "document" instead of the application's "top".
Do you have any ideas to help us solve the problem?
Thanks in advance!
Rui
We have a web application where we're using "top.document" since this application uses iframes and sometimes we must reach the top document.
The problem started now since we need to integrate this application in a website and we put it inside an iFrame in this very site. Since the application uses "top.document" it is reaching the site's "document" instead of the application's "top".
Do you have any ideas to help us solve the problem?
Thanks in advance!
Rui
Share Improve this question asked Nov 5, 2009 at 16:10 RuiRui 111 gold badge1 silver badge2 bronze badges3 Answers
Reset to default 1Assuming your iframe is one level deep:
parent.document
or, if it's deeper:
parent.parent.parent.parent.document
but I really hope it's not that deep ;-)
The approach to ensuring that you are looking at the correct window is to know where you are within the framed application.
For example, let us say the “main frame” is the root of the site. Within the main frame, additional ‘iFrames’ are defined. The pages that are loaded in these additional frames need to know where they are in the frame hierarchy.
So you see, understanding where you are in the hierarchy of frames and pop-ups will allow you to properly backtrack and define references to functions and objects contained within windows in previous pages/frames.
Adding some Javascript code to give you an idea:
if (window.self){
if (window.top == window) {
if (window.name == "main_frame"){
MainFrameRef = window.top;
return MainFrameRef;
} else {
return false;
}
}
}
If you are looking for dead simple, look for known ids, and that's where you stop your upward crawl of parents and tops and docs.
Or you could have each frame register itself in some global variable (namespaced of course) when they load, that way you have a reference to them and do not need to traverse the DOM.
本文标签: javascriptalternative to html topdocument inside iframeStack Overflow
版权声明:本文标题:javascript - alternative to html top.document inside iframe - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745640706a2160728.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论