Javascript Center Popup Window

How to center a chromeless pop-up window in most browsers.

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

Now create a link with a hash in the href attribute and add the javascript call on a onClick command.

<a href="#" onclick="OpenNewWindow('http://freepennysaver.com/','710','548','Loading');" > Popup </a>

Be sure to change the url “freepennysaver.com” to your url.

Leave a Reply