SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New window focus and resize.

    Hi all,

    I am using the new window function i found on the net, but I have tweaked it to re-focus on the window each time an image is opened.

    Code:
    var win=null;
    function NewWindow(mypage,myname,w,h,scroll,pos){
    	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
    	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
    	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
    	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    	win=window.open(mypage,myname,settings);
    	win.focus();
    }
    The function receives variables from the html page that decide the width height etc... And whilst the function will display the new image and focus on the window, it wont resize the window as per the new variables passed from the page. If i close the window and open the link it will resize the window though.

    Any thoughts,
    Paul.

  2. #2
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the resize as in this function ONLY works on new windows. If you want a window to resize which is already open put this code in the onload of mypage (this also centers the new window)
    Code:
            //ie
    	if (!document.all) {
    		window.sizeToContent();
    		window.sizeToContent();	// for reasons beyond understanding,
    					// only if we call it twice we get the
    					// correct size.
    		// center on parent
    		var x = (screen.width - window.outerWidth) / 2;
    		var y = (screen.height - window.outerHeight) / 2;
    		window.moveTo(x, y);
                     // resize ie
    		window.resizeTo(540, 300);
    	} else {
    		window.resizeTo(540, 400);
    
    		var ch = body.clientHeight;
    		var cw = body.clientWidth;
    		var W = body.offsetWidth;
    		var H = 2 * body_height - ch;
    		var x = (screen.availWidth - W) / 2;
    		var y = (screen.availHeight - H) / 2;
    		window.moveTo(x, y);
    	}
    Corinis OpenSource Community & Content Management
    http://www.corinis.org

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hiya,

    cool thanks for that. WOuld it also be possible to add a line to the function to first close the window, automatically, then open a new one thus making the resize happen?

    p.

  4. #4
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure... add
    Code:
    if (win != null)
      win.close()
    Corinis OpenSource Community & Content Management
    http://www.corinis.org


Bookmarks

Posting Permissions

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