Webdesign,code & ...stuff!

Aug 22, 2009

Javascript: window.open pop-up at center

In javascript - window.open opens a popup that by default opens at random location of the window. Below is a javascript function that will open a pop-up in the center of the client window. Hope it may save many additional lines of javascript code.

function popupwindow(windowUri, windowHeight, windowWidth, windowName)
{
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;

newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);

newWindow.focus();
return newWindow.name;
}



Please notice parameters that are passed to window.open.

2 comments:

mariancalago said...

hi,,, can we link exchange pls with my blogs:
Shadows of Me
Movie Reviews
pls let me know. thanks

mariancalago said...

hi., thanks. done adding your blog too in my blogroll.