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

    Referencing and changing other windows....

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

    I have a browser, that when you click on the appropriate area it will open a new window. But I want that new browser to remain in the place where it opens. As such I have created a snap function, that when you move the window it will immediately snap it back into place.

    The problem I am having is that it is snapping the window that is opening the new browser and not the new browser itself. How do I reference the new browser window, can it be done by its name?

    Any help would be appreciated.

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could just make a global var to hold the window...
    Code:
    function NewBrowser(url, thename, h, w, l) {
    // Removed first line...
    string = 'height=' + h + ',width= ' + w + ',top=0, left=' + l + ',resizable=no'
    
           newwindow = window.open(url, thename, string);
    	if (window.focus){
    	newwindow.focus()
    	}
    setInterval("snap2()",500);		
    }
    
    var newwindow; // Gloabl variable holding your window
    
    function snap()
    {
    // Refer to gloabal thruout this function
    try{
    xLoc = newwindow.screenX 
    yLoc = newwindow.screenY
     
    	if (xLoc != 257 & yLoc != 0)
    	{
    		newwindow.moveTo(257,0);
    	}
    	
    }catch(err){}
    }
    As for the name property of the window, this is only useful when specifying a target of some other object (eg <a target="myWindow" href="www.codingforums.com">Click Me!</a> )
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!


  •  

    Posting Permissions

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