www.webdeveloper.com
Results 1 to 5 of 5

Thread: global variable (scope within diff. browser-windows)?

  1. #1
    Join Date
    May 2005
    Posts
    52

    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?

    regards,
    oliver

  2. #2
    Join Date
    Jan 2005
    Posts
    3,067
    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.

  3. #3
    Join Date
    May 2005
    Posts
    52
    ok thx, I will try it out

  4. #4
    Join Date
    Dec 2008
    Posts
    1

    Did you ever find a solution?

    I am also trying to open a popup from both windows A and B and if the popup is already open, I want to reuse it and not open another.

    Did you ever find a solution?

    - Bob

  5. #5
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    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.

    Code:
    myWinStat = window.open(myPath,"windowname","widt....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles