【问题标题】:setting document.domain in IE在 IE 中设置 document.domain
【发布时间】:2015-11-16 22:45:29
【问题描述】:

当我尝试设置 document.domain 时,我在我尝试过的所有 Internet Explorer 版本(IE9、IE11)中都遇到错误

我需要让父级和 iframe 交互。它们都来自同一个域,但不同的子域。

给父母

document.domain = "mydomain.ca";

在 iframe 中

document.domain = "mydomain.ca"

当父加载时,我在控制台中收到以下错误:

SCRIPT87: Invalid argument.

在 Chrome 中一切正常。另外,我正在运行 IE9 兼容模式(以防万一)

更新 11 月 16 日 @ 3:30 太平洋 试过这段代码:

<html>
<head>
    <script type="text/javascript">
            document.domain - document.domain;
            alert(document.domain);
            document.domain = "mydomain.ca";
            alert(document.domain);
    </script>
</head>
<body></body>
</html>

它会给我一个带有当前域的警告框,但之后我收到“无效参数”错误。同样,适用于 Chrome,但不适用于 IE9 和 IE11。

【问题讨论】:

标签: javascript internet-explorer iframe


【解决方案1】:

我通过使用解决了这个问题 parent.postMessage("My data","http://sub.mydomain.com"); 然后在父节点上设置监听器。

这最终可能是一个更好的解决方案。

【讨论】:

    猜你喜欢
    • 2010-12-02
    • 2011-10-13
    • 1970-01-01
    • 2017-10-24
    • 2016-06-12
    • 2013-01-20
    • 2012-05-12
    • 2019-12-19
    • 1970-01-01
    相关资源
    最近更新 更多