Javascript 访问被拒绝 - 在 iframe 中不再使用父级后无法访问 opener
这与具有相同错误消息的许多其他类似帖子一样与域无关。
这是我的设置:
<iframe src='somepage' />
用户可以从某个页面内打开一个弹出窗口,并使用 window.open 。假设我的弹出窗口保持打开状态,并且新的源页面“secondPage”被交换到同一个 iframe 中。我的弹出窗口仍然可以是“开启器”,但每当我尝试访问开启器时,它都会抛出访问被拒绝的脚本错误。
所以我的问题是,我如何访问它或检查它是否关闭,以便我不尝试访问它?我试图检查 window.opener.close 是否已关闭,显然返回的是 false......
This is not related to the domain like many other similar posts with the same error message.
Here is my set up:
<iframe src='somepage' />
user can open a window popup from within somepage and window.open is used. Assume my popup remain open and a new source page 'secondPage' is swapped into the same iframe. My popup can still its 'opener' but whenever i try to access the opener, it will throw an access denied scripting error.
so my question is, how can i either access it or check to see if it closed so i dont try to access it? i tried to check if window.opener.closed and apparently is returning me a false.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的开启器将有一个名为
关闭
的属性,您可以检查它是否已关闭(或导航离开)。如果它已关闭,则检查opener
上的任何其他属性都会抛出错误,因为窗口对象已被销毁。我刚刚注意到您知道
close
属性。我以前用过这个,从来没有遇到过问题。您使用什么浏览器?发布您正在运行的代码。如果全部失败,请使用
try catch
检测访问 opener 时是否发生错误。IE IFRAME 错误
您所描述的内容在评论中被列为错误
http://msdn.microsoft.com/en-我们/库/ms533574(v=VS.85).aspx
Your opener will have a property called
closed
which you can check to see if it's has been closed (or navigated away). If it's closed, checking any other property on theopener
will throw an error because the window object has been destroyed.I just noticed that you knew about the
closed
property. I've used this before and I never had problems.What browser are you using? Post the code you're running. If all fails, use a
try catch
to detect that an error occurred while accessing the opener.IE IFRAME BUG
What you've described is listed as bug in a comment on
http://msdn.microsoft.com/en-us/library/ms533574(v=VS.85).aspx