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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to center a popup window?

    Hello I am using this script to open multiple popup windows of various sizes. The code was kindly provided by glenngv (thanks works great) but since they are various window sizes a static set dimension of where the window is placed wont work example: top=50, left=200' what I need is to find out how to center the popup no mater of the size of the popup

    <script>
    function popitup(url, w, h)
    {
    var newW = w + 100; //add border
    var newH = h + 100; //add border
    var newwindow=window.open(url, 'name', 'height='+newH+', width='+newW+', top=50, left=200');
    newwindow.resizeTo(newW, newH); //if popup window is already open, the size specified in window.open does not take effect, so we need to resize it.
    newwindow.focus();
    return false;
    }
    </script>

    Link for popup:
    <a href="/games/pool.php" onclick="return popitup(this.href, 500, 400)">3D Pool Deluxe</a>

    Thanks
    Shawn

    and props to glenngv for providing the origonal coding

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need is to find out how to center the popup no mater of the size of the popup
    Center to what? Room, earth, universe?
    rm -f /

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    That deserves a screenshot and post someplace so we can all laugh at you...

    Well I thought I was pretty explanitory but in case you are misinformed. You see there is this monitor here and I was discussing on the forums how to center a popup window (*hence the title of the post) How to center a popup window?

    If I am using the examples of top=50, left=200 and described that I want it to not use width and height but to center the popup on the CENTER of the screen. I would hope someone would understand.

    I do apologize that for some twisted reason you might of concluded I was discussing a popup window in a center of a room or a javascript popup window in the center of the universe...bah

    If anyone knows the answer to my origonal post it would be appreciated
    Thanks
    Shawn

  • #4
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    function popitup(url,newH,newW)
    { var left = (screen.width-newW)/2;
    var top = (screen.height-newH)/2;
    var newW = w + 100;
    var newH = h + 100;
    myWindow = window.open(url, 'name', 'width='+newW+',height='+newH+',left='+left+',top='+top);
    myWindow.resizeTo(newW, newH);
    myWindow.moveTo(left, top);
    myWindow.focus();
    }

    hope this works...

    - NS 666
    .net DEVILoper

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    antimedia

    For your information: you can center popupwindow to: monitor screen, parent window, a frame or anything else. As mind reading has not been developed yet, you should be more specific.

    That deserves a screenshot and post someplace so we can all laugh at you...
    I already showed mine coworkers your post, we really enjoyed the one.
    Last edited by rm-f; 10-20-2005 at 06:15 PM.
    rm -f /

  • #6
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    oops... i think i made a mistake...
    the variables left and top should be assigned values after newH and newW are altered to accomodate for the border...

    Code:
    function popitup(url,newW,newH)
    {
    var newW = w + 100;
    var newH = h + 100;
    var left = (screen.width-newW)/2;
    var top = (screen.height-newH)/2;
    var newwindow = window.open(url, 'name', 'width='+newW+',height='+newH+',left='+left+',top='+top);
    newwindow.resizeTo(newW, newH);
    
    //this line will move the popup to the center of... NOT THE UNIVERSE...
    newwindow.moveTo(left, top);
    
    newwindow.focus();
    return false;
    }
    now... it seems perfect...
    - NS 666
    .net DEVILoper


  •  

    Posting Permissions

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