Announcement

Collapse
No announcement yet.

Center a pop up

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Center a pop up

    I actually use the following function, to open a pop up page :
    function ShowPopUp(sUrl, nWidth, nHeight)
    {
    window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
    if (!bPageIsLoaded)
    {
    window.location.reload(true);
    }
    }

    How can I whange it to get a center pop up ?
    Thanks
    Didier
    www.supreme.fr
    _____________________
    Saint Malo. France

    #2
    Isn't there a top, left or x,y co-ordinate you can add to the parameters? something like

    Code:
    window.open("about:blank", "newwindow", height=150,width=300,top=10,left=10,resizable=yes");

    Comment


      #3
      Yes, I changed to
      window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',top=10,left=10, scrollbars, resizable');
      and I get the pop up not in the center but at always the same place in the top right handside of the screen.
      Thanks for your help.
      Didier
      www.supreme.fr
      _____________________
      Saint Malo. France

      Comment


        #4
        Keep in mind users with small monitors and even hand held devices that may be visiting your site... if you posiiton off screen and they are unable to close the pop-up you could cause havoc.


        Bikster
        SellerDeck Designs and Responsive Themes

        Comment


          #5
          This pop up will open at top 10 and left 10 and size is 785 * 610, so I think it must be good. If not is there another solution ?
          Didier
          www.supreme.fr
          _____________________
          Saint Malo. France

          Comment


            #6
            I guess Jo's suggestion was the best here.

            Kind regards,
            Bruce King
            SellerDeck

            Comment


              #7
              I changed the code to get the exact size I need at the good place.
              Thanks
              Didier
              www.supreme.fr
              _____________________
              Saint Malo. France

              Comment


                #8
                A bit late, but handy bit of DHTML will auto-center popup windows...

                Within <head></head>...
                Code:
                <script language="javascript">
                
                var win = null;
                function centerpop(mypage,myname,w,h,scroll){
                leftposition = (screen.width) ? (screen.width-w)/2 : 0;
                topposition = (screen.height) ? (screen.height-h)/2 : 0;
                settings =
                'height='+h+',width='+w+',top='+topposition+',left='+leftposition+',scrollbars='+scroll+',resizable'
                win = window.open(mypage,myname,settings)
                }
                
                </script>
                Then for the link...

                Code:
                <a href="http://yourlink.com" onclick="centerpop(this.href,'name','400','400','yes');return false">Link Text</a>
                name = Title of the popup window
                400 = width of popup
                400 = height of popup
                yes = scrollbars (yes / no)
                Cheers!
                Marci - <a href="http://www.Over-Clock.co.uk" target="_blank">www.Over-Clock.co.uk</a>

                Comment


                  #9
                  Thanks MArk, it seems very good !
                  Didier
                  www.supreme.fr
                  _____________________
                  Saint Malo. France

                  Comment

                  Working...
                  X