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

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »