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
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Help with centering a window popup

    Hi,

    Can someone assist in modifying this code so that the popup is centered on the page?

    function popImg(which){
    var theImg = new Image();
    theImg.src = which;
    var imgw = theImg.width;
    var imgh = theImg.height;

    if(imgw<600){imgw = 600};
    if(imgh<400){imgh = 400};

    var imgWin = window.open('','popImg',config='height='+imgh+
    ',width='+imgw+',top=0,right=100');

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Try (screen.availHeight - imgh)/2.0 and (screen.availWidth - imgw)/2.0 for top and right, respectively.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    The following seems to work. If you see an extraneous code, please let me know?

    function popImg(which){
    var theImg = new Image();
    theImg.src = which;
    var imgw = theImg.width;
    var imgh = theImg.height;
    var w=(screen.width-600)/2;
    var h=(screen.height-400)/2;

    if(imgw<600){imgw = 600};
    if(imgh<400){imgh = 400};

    var imgWin = window.open('','popImg',config='height='+imgh+
    ',width='+imgw+',top='+h+',left='+w+'');


  •  

    Posting Permissions

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