JavaScript: How to alert variable on window.opener
Opened Windo开发者_开发问答w:
window.opener.variable = document.getElementById(target).value; //string
window.opener.focus();
Window Opener
alert(variable);
Could this be done? The above example doesn't work.
This can be done, but not across different domains.
If you want to cause the original window to alert the variable:
window.opener.alert(variable);
Testcase:
Type javascript:void window.open("http://stackoverflow.com/");
in this window. A new window will open.
Type javascript:void window.opener.alert(location.href);
in the location bar of the new window, and press Enter. The original window will show an alert box.
I have successfully executed this in FireFox 3.6.22 and the newest version of Chromium. When I open "http://www.example.com/" instead of "http://stackoverflow.com/", a JavaScript error will occur, caused by the same-origin policy.
精彩评论