Javascript : Open a pop-up center window

71
rate or flag this page

By aslgomes


Javascript : Open a pop-up center window

I was having trouble focusing on the screen a new window that was open through a javascript function, until today to demand in some forums discovered a way of doing it.

This way is valid for any resolution because the calculation of the position of the window is based on the size of each screen:

function openWindow()
{
 
      var winW = 600;
      var winH = 400;
      var winX = (screen.availWidth - winW) / 2;
      var winY = (screen.availHeight - winH) / 2;
 
      var features = 'left=' + winX + ',top=' + winY + 
                     ',height=' + winH + ',' + 'width=' + 
                     winW + ',status=yes,' + 'toolbar=no,
                     menubar=no,location=no';
 
      window.open('Teste.aspx', null, features);
 
      return false;
}
 

I hope this may be useful to someone.

This post is on my personal blog too, in portuguese languange, here.


Print   —   Rate it:  up  down  [flag this hub]

Comments

RSS for comments on this Hub Small RSS Icon

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working