Is there any way to open a new window with,
var newWindow = window.open(...);
and then pass events from newWindow to its opener window?
What I want to do is open a window that asks for some information, then once it’s been entered close the new window and trigger an action in the original window.
Thanks.
edit: Thanks all. That’s pretty much how I thought it worked, but I must be doing something stupid. Here’s some test code I’ve been banging my head against a wall over:
in parent.html
window.open("child.html");
$(window).bind("something", function(e) {
console.log('something happened');
});
and in child.html
$("#somebutton").click(function() {
$(window.opener).trigger("something");
window.close();
});
child opens fine, I click the button and child closes, but “something” never happens in parent!?
I’d kind of like it to work the other way around too. Any way to make something like this work?
var child = window.open("child.html");
$(child).bind("something", function() { ... });
Thanks.
I hesitate to plug jQuery unnecessarily, but it is quite nice for things like this:
Just run that line in the initialization script of the child window. Note: the even must obviously be bound to the
bodyelement in the parent.Note that you are limited by single-origin policy here. Unless explicitly permitted by the browser, this will only work if both windows are opened from the same host.