I open a new tab using window.open. The new tab has a javascript myfunction
function in it defined in a script tag. From the window that opens the new window, I want to run that function.
How can I do that?
Thanks
Something like
var a = window.open("mypage.html", "_blank");
a.myfunction("hi");
EDIT
This isn't working. Its not doing the alert.
opener
var w = window.open("../scripts/map.php", "_blank");
w.postMessage("The user is 'bob' and the password is 'secret'", "*");
new tab
function receiveMessage(event) {
alert(event.data);
}
window.addEventListener("message", receiveMessage, false);
The JavaScript call() Method The call() method is a predefined JavaScript method. It can be used to invoke (call) a method with an owner object as an argument (parameter). With call() , an object can use a method belonging to another object.
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
var a = window.open("mypage.html", "_blank");
a.focus();
a.addEventListener('load', function(){
a.myfunction("hi");
}, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With