global variable (scope within diff. browser-windows)?
hello fellow people,
I've got a nice tiny JS, which pops up a pop-up. if it is already open, there won't be any new one, it will just be focused:
Code:
var myWinStat;
function popStat(myPath, myHeight, myWidth) {
if(myWinStat && !myWinStat.closed){
myWinStat.focus();
} else {
myWinStat = window.open(myPath,"","width="+myWidth+",height="+myHeight+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,left=50,top=50");
myWinStat.focus();
}
}
now, I want exactly the same functionality, but from more than one mother-browserwindow. which means: if I open the pop-up from browser-window A, it shall not be created again if I reopen it from browser-window B (only moved to the foreground). In other terms, I need a global variable (var myWinStat;) which is known in all different browser-windows. is this possible to solve?
I don't know if this works cross browser, but the following code will open a window and not allow for it to be opened again:
Code:
function popitup2()
{
newwindow2=window.open('','name','height=200,width=150');
var tmp = newwindow2.document;
tmp.write('<html><head><title>popup</title>');
tmp.write('<link rel="stylesheet" href="js.css">');
tmp.write('</head><body><p>this is once again a popup.</p>');
tmp.write('<p><a href="javascript:alert(self.location.href)">view location</a>.</p>');
tmp.write('<p><a href="javascript:self.close()">close</a> the popup.</p>');
tmp.write('</body></html>');
}
since there is no:
tmp.close();
at the end of the code the window can't be opened multiple times . . . supposedly. I am not sure if this works perfectly, but I have been told that it does.
The second parameter in the window.open command is the name of the window. If you use anything other than a value starting with an underscore then if a window by that name is already open it will reuse that one instead of opening a new one.
Bookmarks