Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help!! Variable being wiped......

    Code:
    function NewBrowser(url, thename, h, w, l) {
    		string = 'height=' + h + ',width= ' + w + ',top=0, left=' + l + ',resizable=no';
    		var newwindow = window.open(url, thename, string);
    		if (window.focus) {
    			newwindow.focus();			
    		}
    		myArray['main'] = newwindow;
    		timeout()
    		
    }
    
    function timeout()
    {
    setInterval("snap(myArray['main'])", 500);
    }
    
    
    function snap(windowObj) {
    	try {
    
    		xLoc = windowObj.screenX;
    		yLoc = windowObj.screenY;
     
    		if (xLoc != 257 & yLoc != 0) {
    			windowObj.moveTo(257, 0);
    		}	
    	} catch(err) { 
    		
    	}
    }


    This is my code, and it works...kinda. When I click on my link and open a new browser, as its loading if I move the browser it will snap back into position. When the page loads completely this stops working. Its like the variable myArray['main'] is being overwritten.

    Could anyone shed any light?

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    try defining the variable in the global scope:

    Code:
    var myArray; // *** Ensure the variable is defined globally ***
    
    function NewBrowser(url, thename, h, w, l) {
    		string = 'height=' + h + ',width= ' + w + ',top=0, left=' + l + ',resizable=no';
    		var newwindow = window.open(url, thename, string);
    		if (window.focus) {
    			newwindow.focus();			
    		}
    		myArray['main'] = newwindow;
    		timeout();	
    }
    
    function timeout()
    {
      setInterval("snap(myArray['main'])", 500);
    }
    
    function snap(windowObj) {
    	try {
    
    		xLoc = windowObj.screenX;
    		yLoc = windowObj.screenY;
     
    		if (xLoc != 257 & yLoc != 0) {
    			windowObj.moveTo(257, 0);
    		}	
    	} catch(err) { 
    		
    	}
    }
    See if that works.


  •  

    Posting Permissions

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