Window.opener Is Returing Null
I have a link in www.abc.com , clicking on which it opens up a popup from www.def.com . There is a form in that popup from www.def.com. After clicking upon the 'Save' button on the
Solution 1:
At "abc.moc"
<!DOCTYPE html><html><head><script>// open `popup`var popup = window.open("popup.html", "popup", "width=200,height=200");
// handler `message` event from `popup.html`functionreceiveMessage(event) {
console.log(event, event.data);
this.location.href = event.data;
}
window.addEventListener("message", receiveMessage, false);
</script></head><body></body></html>
at "def.moc"
<!DOCTYPE html><html><head></head><body><form><inputtype="button"value="Save"></form><script>console.log(window.opener);
var button = document.querySelector("form input[type=button]");
button.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
// do stuff with `form`// call `.postMessage()` on `window.opener` with // first parameter URL to redirect `abc.moc`,// second parameter `location.href` of `abc.moc`window.opener.postMessage("redirect.html",
window.opener.location.href);
// close `popup`window.close();
}
</script></body></html>
plnkr http://plnkr.co/edit/pK4XBJDrqFrE7awvMlZj?p=preview
Post a Comment for "Window.opener Is Returing Null"