问题描述
我有一个ASP.NET网站,我在其中嵌入了iframe并在其中打开了第三方网站,即我没有该网站的控件。现在该网站在许多地方使用带有window.top的javascript来访问元素,例如:
I have an ASP.NET website in which I embedded an iframe inside a page and open a third party website inside it, i.e. I do not have a control on that website. Now that website uses a javascript with "window.top" at many places to access elements, like:
window.top.$('#elementid')...
问题是网站在iframe中打开,第三方网站内的顶部是指最顶层的浏览器窗口,这是我的网站页面,而不是他们的网站。所以它不会获得它使用的id元素。所以它抛出了javascript错误而没有正确加载。当我在新标签页面中打开该网站时,它正确加载。
您能否为我提供解决方案,使顶部引用iframe本身?
我尝试了什么:
使用window.self可以解决问题,但我无法修改第三方网站的javascript。所以我需要一些其他解决方案。该网站也必须仅显示在我的网站页面内。
The problem is as the website is opened in an iframe, "top" inside third party website refers to topmost browser window which is my website page, and not their website. So it will not get elements with id it uses. And so it throws javascript errors and not loaded correctly. When I open that website in new tab, it loads correctly.
Can you provide me the solution to make "top" refer to the iframe itself?
What I have tried:
Using "window.self" can resolve the problem, but I cannot modify javascript of third-party website. So I need some other solution. Also that website must be displayed inside my website page only.
推荐答案
问题是网站在iframe中打开,第三方网站内的顶部是指最顶层的浏览器窗口,这是我的网站页面,而不是他们的网站。所以它不会获得它使用的id元素。所以它抛出了javascript错误而没有正确加载。当我在新标签页面中打开该网站时,它正确加载。
您能否为我提供解决方案,使顶部引用iframe本身?
我尝试了什么:
使用window.self可以解决问题,但我无法修改第三方网站的javascript。所以我需要一些其他解决方案。此网站也必须仅显示在我的网站页面内。
The problem is as the website is opened in an iframe, "top" inside third party website refers to topmost browser window which is my website page, and not their website. So it will not get elements with id it uses. And so it throws javascript errors and not loaded correctly. When I open that website in new tab, it loads correctly.
Can you provide me the solution to make "top" refer to the iframe itself?
What I have tried:
Using "window.self" can resolve the problem, but I cannot modify javascript of third-party website. So I need some other solution. Also that website must be displayed inside my website page only.
这篇关于iframe问题与window.top有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!