我正在使用来自 fancybox 插件的 iframe。我可以使用 javascript 命令关闭每个浏览器中的 iframe,除了 google chrome:
parent.$.fancybox.close();
或者:
parent.jQuery.fancybox.close();
在这种情况下,只是 google chrome 拒绝做他的工作。
控制台的错误信息是:
不安全的 JavaScript 尝试从具有 URL file:///C:/Users/exampleuser/Desktop/Version42/index 的框架访问具有 URL file:///C:/Users/exampleuser/Desktop/index.html 的框架。 HTML#。域、协议(protocol)和端口必须匹配。 pidgin.js:357Uncaught TypeError: 无法读取未定义的属性 'fancybox'
如果重要的话,我的框架目前是本地的。
最佳答案
尝试使用 parent.postMessage()
( described here ) 并监听父级的 window.onmessage
以调用 $.fancybox.close( )
。
关于javascript - 无法关闭谷歌浏览器中的 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10008584/