【问题标题】:Cant close an iframe in google chrome无法在谷歌浏览器中关闭 iframe
【发布时间】:2012-04-18 00:16:26
【问题描述】:

我使用来自 fancybox 插件的 iframe。我可以使用 javascript 顺序关闭每个浏览器中的 iframe,除了 google chrome:

parent.$.fancybox.close();

或:

parent.jQuery.fancybox.close();

在这种情况下,只是谷歌浏览器拒绝做他的工作。

控制台的错误信息是:

不安全的 JavaScript 尝试从具有 URL 文件:///C:/Users/exampleuser/Desktop/Version42/index 的框架访问具有 URL 文件:///C:/Users/exampleuser/Desktop/index.html 的框架。 html#。域、协议和端口必须匹配。 pidgin.js:357Uncaught TypeError: Cannot read property 'fancybox' of undefined

如果这很重要,我的框架目前是本地的。

【问题讨论】:

    标签: javascript iframe fancybox


    【解决方案1】:

    您的代码没有问题,但 Google Chrome 不会让您在本地使用 ajax 或 iframe(和 fancybox)。您需要将文件上传到服务器才能使其正常工作。

    【讨论】:

      【解决方案2】:

      尝试使用parent.postMessage() (described here) 并监听父级的window.onmessage 以调用$.fancybox.close()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多