The problem with document.write in iframe in Edge

Issue #9291485 • Assigned to Travis L.

Details

Created
Oct 11, 2016
Privacy
This issue is public.
Found in
  • Microsoft Edge
Reports
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

The document.write causing the error SCRIPT70: Permission denied if you use a few document.write inside iframe. This error occurs only in the Edge. In all other browsers this error is not observed.
For example:

<!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>

This code will display 12 on the page and in iframe, but it cause an error and displays only 1 inside iframe in Edge.

However, If you add window in front of document.write the error will not be caused.

<!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>

But it still looks like a bug.

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Brad E.”

      Changed Assigned To to “Travis L.”

    You need to sign in to your Microsoft account to add a comment.

    Sign in