Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
143
rated 0 times [  144] [ 1]  / answers: 1 / hits: 20768  / 10 Years ago, wed, august 27, 2014, 12:00:00

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);

More From » jquery

 Answers
5
var a = window.open(mypage.html, _blank);
a.focus();

a.addEventListener('load', function(){
a.myfunction(hi);
}, true);

[#69646] Sunday, August 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leighamarleem

Total Points: 75
Total Questions: 121
Total Answers: 111

Location: Norway
Member since Mon, May 23, 2022
2 Years ago
;