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;
if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
// end script here -->

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

<a href="#" onclick="OpenNewWindow('','710','548','Loading');" > Popup </a>

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

Leave a Reply