How to open a centered pop-up window in Javascript
Here is a Javascript function that allows you to open a centered window, no matter what resolution the visitor uses.
function OpenCenteredWindow( url, width, height )
{
var left = Math.floor( (screen.width - width) / 2);
var top = Math.floor( (screen.height - height) / 2);
var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
winParms += ",toolbar=no,status=no,scrollbars=yes,menubar=no,resizable=no,location=no,directories=no";
var win = window.open(url, '', winParms);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
return win;
}
There are three parameters:
- url - the address you want to open in the new window
- width - the width of the new popup window
- height - the height of the new centered window
No comments:
Post a Comment