Javascript 边缘中的几个document.write-in-iframe原因SCRIPT70:权限被拒绝

Javascript 边缘中的几个document.write-in-iframe原因SCRIPT70:权限被拒绝,javascript,iframe,microsoft-edge,Javascript,Iframe,Microsoft Edge,document.write导致错误SCRIPT70:如果在iframe中使用了一些document.write,则权限被拒绝。此错误仅发生在边缘。在所有其他浏览器中均未观察到此错误。 例如: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>SSP-558</title> </head> <body&

document.write导致错误SCRIPT70:如果在iframe中使用了一些document.write,则权限被拒绝。此错误仅发生在边缘。在所有其他浏览器中均未观察到此错误。 例如:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SSP-558</title>
</head>
<body>
<script>
    document.write("1");
    document.write("2");
</script>
<script>
    var iframe = document.createElement("iframe");
    iframe.width = window.outerWidth;
    iframe.height = window.outerHeight;
    iframe.onload = function () {
        var doc = iframe.contentWindow.document;
        var script = doc.createElement("script");
        script.type = "text/javascript";
        script.text = [
            'document.write("1");',
            'document.write("2");'
        ].join("");

        doc.body.appendChild(script);
    };
    document.body.appendChild(iframe);
</script>
</body>
</html>

SSP-558
文件。填写(“1”);
文件。填写(“2”);
var iframe=document.createElement(“iframe”);
iframe.width=window.outerWidth;
iframe.height=window.outerHeight;
iframe.onload=函数(){
var doc=iframe.contentWindow.document;
var script=doc.createElement(“脚本”);
script.type=“text/javascript”;
script.text=[
“文档。写入(“1”);”,
'文档。写下(“2”);'
].加入(“”);
doc.body.appendChild(脚本);
};
document.body.appendChild(iframe);
此代码将在页面和iframe中显示12,但会导致错误,并且在Edge中的iframe中仅显示1

如果您只使用一个文档,请编写所有文档。不幸的是,包含多个document.write的代码来自第三方开发人员,他们无法对其进行更改


您是否遇到此错误,是否有解决方法?

已找到解决方法。如果在document.write前面添加窗口,则不会导致错误

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SSP-558</title>
</head>
<body>
<script>
    document.write("1");
    document.write("2");
</script>
<script>
    var iframe = document.createElement("iframe");
    iframe.width = window.outerWidth;
    iframe.height = window.outerHeight;
    iframe.onload = function () {
        var doc = iframe.contentWindow.document;
        var script = doc.createElement("script");
        script.type = "text/javascript";
        script.text = [
            'window.document.write("1");',
            'window.document.write("2");'
        ].join("");

        doc.body.appendChild(script);
    };
    document.body.appendChild(iframe);
</script>
</body>
</html>

SSP-558
文件。填写(“1”);
文件。填写(“2”);
var iframe=document.createElement(“iframe”);
iframe.width=window.outerWidth;
iframe.height=window.outerHeight;
iframe.onload=函数(){
var doc=iframe.contentWindow.document;
var script=doc.createElement(“脚本”);
script.type=“text/javascript”;
script.text=[
“window.document.write(“1”);”,
'window.document.write(“2”);'
].加入(“”);
doc.body.appendChild(脚本);
};
document.body.appendChild(iframe);

如果使用更多的写入或完全不同的js会发生什么?。如果没有任何帮助,请将iframe内容和js移动到单独的html文件中,并仅从此脚本调用该文件。这应该可以防止任何安全错误。有趣的是,第一次写入不需要
窗口。文档
在没有窗口的情况下可以工作,但之后所有其他写入都需要窗口部分。。。奇怪的是,虽然我没有使用iframe,但这也修复了我的SCRIPT70:在尝试使用document.write(“”)时被拒绝的权限。在前面添加了window.document.write(“”),解决了错误。