SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you center the a pop-up window on the screen after a mouseclick on a button?

  2. #2
    Bimbo With A Brain! silver trophy Saz's Avatar
    Join Date
    Mar 2001
    Location
    Kent, United Kingdom
    Posts
    5,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only way I know is to state the number of pixels from the left and from the top.

    i.e.

    function openPopup(url_param) {
    var popupWin = null;
    popupWin = window.open(url_param, 'remote', 'width=400,height=375,resizable=no,menubar=no,toolbar=no,left=200, top=100,scrollbars=yes')
    popupWin.opener.name="main";

    }


    Hope this helps
    Saz
    The Postfive Website
    Postfive Publishing

  3. #3
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to check this out
    http://tech.irt.org/articles/js128/#2.2

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much! I really appreciate the help!

  5. #5
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So to center a window, you'd use something like:

    Code:
    windowWidth=define Width of new window;
    windowHeight=define Height of new window;
    ww=(screen.availWidth-windowWidth)/2;
    hh=(screen.availHeight-windowHeight)/2;
    window.open('somepage.html','','width='+windowWidth+',height='+windowHeight+',top='+wh+',left='+ww+',screenY='+wh+',screenX='+ww);
    aDog

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a little confused with that last script. As I understand it, this script is designed to compensate for all resolutions and monitor sizes, correct? Well, here's what I didn't understand..

    +windowWidth+

    Do I type that as is? Is that a variable? I'm sorry, my Javascript is not that good, and I was wondering if you could clear this up for me.

    Thanks!

  7. #7
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Those are just variables I made. What you'd do is fill in the width and height of the new window you want here:

    windowWidth=define Width of new window;
    windowHeight=define Height of new window;

    Anyone know why there's a space here:

    ,screen X='+ww);

    when it should be:

    ,screenX='+ww);

    That's in my post, but it shows up on screen witht he space.

    aDog

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I get it. Thanks!

  9. #9
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Arielladog
    Anyone know why there's a space here:

    ,screen X='+ww);

    when it should be:

    ,screenX='+ww);

    That's in my post, but it shows up on screen witht he space.

    aDog
    You might want to go back to your post and try editing so someone doesn't try using it without noticing the space.

  10. #10
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see what I could try to edit...

    aDog


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
  •