JavaScript: how to warn a variable on window.opener

Open window:

 window.opener.variable = document.getElementById(target).value; //string
 window.opener.focus();

Opener for windows

alert(variable);

Can this be done? The above example does not work.

+5
source share
1 answer

This can be done, but not in different domains.

If you want to force 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. A warning window will appear in the original window.

I successfully completed this in FireFox 3.6.22 and the latest version of Chromium. When I open "http://www.example.com/" instead of "http://stackoverflow.com/", a JavaScript error occurs caused by a policy of the same origin.

+3

All Articles