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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Centering a popup help

    I know this is rather basic, but I have a script that I am using to open a pop up once a browser session. I would like to modify it to open the window in the center of the screen instead of top left

    <script>
    function openpopup(){
    var popurl="jetdry.html"
    winpops=window.open(popurl,"","width=200,height=190,")
    }

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
    offset += search.length
    // set index of beginning of value
    end = document.cookie.indexOf(";", offset);
    // set index of end of cookie value
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }

    function loadornot(){
    if (get_cookie('poppedup')==''){
    openpopup()
    document.cookie="poppedup=yes"
    }
    }

    loadornot()
    </script>

    Thanks to anyone who has time to help

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this to open a centered popup window...

    Code:
    <script>
    function openpopup()
    {
    	var popurl="jetdry.html"
    
    	zWinWide=200; // Configure for popup window's width
    	zWinHigh=190; // Configure for popup window's height
    
    	zAttrib=''; // Configure for popup window's attributes (noresize, scrollbars=no, etc.)
    
    	zScrWide=screen.width; // Leave me alone.
    	zScrHigh=screen.height; // Leave me alone.
    
    	zLeftPos=(zScrWide/2)-(zWinWide/2); // Leave me alone.
    	zTopPos=(zScrHigh/2)-(zWinHigh/2); // Leave me alone.
    
    	winpops=window.open(popurl, '', 'width=' + zWinWide + ',height=' + zWinHigh + ',left=' + zLeftPos + ',top=' + zTopPos + ','+zAttrib);
    }
    
    
    function get_cookie(Name)
    {
    	var search = Name + "=";
    	var returnvalue = "";
    
    	if (document.cookie.length > 0)
    	{
    		offset = document.cookie.indexOf(search);
    
    		if (offset != -1) // if cookie exists
    		{
    			offset += search.length;
    			// set index of beginning of value
    
    			end = document.cookie.indexOf(";", offset);
    			// set index of end of cookie value
    
    			if (end == -1) end = document.cookie.length;
    
    			returnvalue=unescape(document.cookie.substring(offset, end));
    		}
    	}
    
    	return returnvalue;
    }
    
    
    function loadornot()
    {
    	if (get_cookie('poppedup')=='')
    	{
    		openpopup();
    		document.cookie="poppedup=yes";
    	}
    }
    
    loadornot()
    </script>

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thanks!

    Thank you very much for your time! It works like a charm.

    kovalik


  •  

    Posting Permissions

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