SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with popup window w/ javascript

    I have found some javascript code and changed it to open a new window upon load that is the width & height of the users screen. I can't seem to figure out how to get it to automaticly center the window on the users screen. The code I have so far is:

    PHP:<script>

    function
    openpopup(){


    w = screen.width;
    h = screen.height;
    ah = h - 25


    var popurl="http://mydomain.com/index.php"
    winpops=window.open(popurl,"",'toolbar=yes,location=no,directories=no,menubar =no,scrollbars=yes,status=no,resizable=1,width='+w
    +',height='+ah)
    window.nw.moveTo(0,0)
    }

    openpopup()

    </script>


    I found this code that will automaticly center the window to the users screen, but can't seem to figure out how to integrate it into my code above.


    Any help on getting the window to automaticly center to the users screen would be greatly appreciated.

    Brandon
    PHP:<!-- Begin
    function NewWindow(mypage, myname, w, h, scroll) {
    var
    winl = (screen.width - w) / 2;
    var
    wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl
    +',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
    if (
    parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    }
    // End -->
    </script>

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I found some code that works. My question now is, does anyone know how to make this code more reliable across multiple browsers, browser versions etc. I read "The Perfect Popup" article, but I'm not sure how to apply it to this code:

    Code:
     <script language=javascript>
    
    	function popper14(){
    
    	var h;var w;var t;var l;
    
    	w=screen.availWidth;
    
    	h=screen.availHeight;
    
    	t=(screen.height-h)/2;
    
    	l=(screen.width-w)/2;
    
    	var Win = window.open('http://www.mydomain.com/index. htm','','width='+w+',height='+h+',top='+t+',left='
    +l+',location=no, statusbar=no, directories=no, resizable=yes, menubar=no, toolbar=yes, scrollbars=yes');Win.focus();
    
    	}
    
    	
    
    	popper14();
    
    	</script>
    Thanks,
    Brandon


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
  •