Auto centering popup window

[Total: 0    Average: 0/5]

This example centers the window on the screen.

Head Code:

<script type=text/javascript>
var win= null;
function NewWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
</script>

Body Code:

<a href="http://www.js-examples.com/" onclick="NewWindow(this.href,'name','400','400','yes');return false">
click to open new window
</a>

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *