krux / postscribe

Asynchronously write javascript, even with document.write.
MIT License
986 stars 157 forks source link

It does not work in Firefox when using a dynamically created iframe with a text #463

Open Tymvie opened 7 years ago

Tymvie commented 7 years ago

The iframe content is hidden after a short period of time Unit test

musikele commented 4 years ago

Just hit this bug. Don't know how to overcome this because postscribe is used by a library that will inject my code. My test page is:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>

<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/postscribe/1.4.0/postscribe.min.js"></script>
    <style>
        #mydiv {
            margin: 5px;
            padding: 5px;
            border: 1px solid red;
        }
    </style>

    <div id="mydiv"></div>
    <script>
        var ad = `
<div id="test"></div>
<script>var div = document.getElementById("test");
var iframe = document.createElement("iframe");
div.appendChild(iframe);
var iframeDocument = iframe.contentDocument;
var internalDiv = iframeDocument.createElement("div");
internalDiv.id = div.id;
var internalScript = document.createElement("script");
internalScript.src= "https://code.jquery.com/jquery-3.4.1.slim.min.js";
iframeDocument.open();
iframeDocument.write(internalDiv.outerHTML + internalScript.outerHTML);
iframeDocument.close();
<\/script>
`;

    postscribe('#mydiv', ad);
    </script>
</body>

</html>

In the iframe I should have seen jquery loaded, but it is not.

Is there any way to circumvent or hack this behaviour?