Reputation: 171
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.
If you use only one document.write everything works fine. Unfortunately, the code that contains several document.write comes from a third-party developers and they can't change it.
Have you encountered this error and is there any solution for it?
Upvotes: 3
Views: 1634
Reputation: 171
There was found a solution. 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>
Upvotes: 4