Javascript popup window

By | June 17, 2010

We always face the problems with popup window in JavaScript using window. Open command either in Custom content or pages that we design. Sometimes the parent window goes blank or sometimes the popup window looses focus and goes behind.

Problem Definition:

Suppose I want to open http://www.google.com in popup window. So ideally I will use below code to do the same in my client side script.

window.open(‘http://www.google.com‘,’PreviewWindow’,’height=600,width=800,status=yes,toolbar=no,menubar=no,location=no’)

What happens here is that javascript uses the same current window object to open new window due to which the parent window gets disturbed. To resolve this we can tweak the code as follows with some more javascript :-).

Resolution:

//Call the function to open popup window
OpenWindow(‘http://www.google.com’)

//Script for window open
function OpenWindow(url)
{
var newwindow;
newwindow=window.open(url,’name’,’height=400,width=200′);
if (window.focus)
{
newwindow.focus()
}
}

Happy scripting 🙂 :-)..

If you find this content useful, Please drop us an email at crm@greytrix.com.