Skip to content

Instantly share code, notes, and snippets.

@NiklasHansen
Created June 25, 2018 11:06
Show Gist options
  • Save NiklasHansen/e9fe3470187e8ce30224b03bcb14fdc0 to your computer and use it in GitHub Desktop.
Save NiklasHansen/e9fe3470187e8ce30224b03bcb14fdc0 to your computer and use it in GitHub Desktop.
Internet Explorer issue, regarding opener.postMessage
<!DOCTYPE html>
<html>
<head>
<title>Child page</title>
<meta charset="utf-8" />
</head>
<body>
Return value: <input type="text" id="returnValue">
<p>Click the button to close the browser window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var returnValue = document.getElementById("returnValue").value;
opener.postMessage({ 'returnValue': returnValue }, "*");
window.close();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Main page</title>
<meta charset="utf-8" />
</head>
<body>
<p>Click the button to open a new browser window.</p>
<p>Returned: <span id="returnValue"></span></p>
<button onclick="myFunction()">Try it</button>
<script>
function myCallback(ejendomsnummer) {
document.getElementById("myParagraf").innerHTML = ejendomsnummer;
}
function myFunction() {
var myWindow = window.open("ChildPage.html", "Ejendomsidentifikation");
}
window.addEventListener("message", function (e) {
var event = e;
document.getElementById("returnValue").innerHTML = event.data.returnValue;
}, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment