View Full Version : Launch a window on pop-up?

11-25-2008, 07:14 PM

On my site I want to launch a window when the page loads, which i've done like so:

<body onload="window.open('survey/front.php', 'newWindow', 'scrollbars=0,resizable=0,height=490,width=640')">

But is this the best way to do it? Is there a better way either in CSS and will this conform to the W3C?

Thank you

11-25-2008, 07:23 PM
This is almost the correct way of doing it. The only thing to do regarding best practice is to move all JavaScript out of the HTML into an external file (this is called unobtrusive JavaScript (http://onlinetools.org/articles/unobtrusivejavascript/index.html)) and only put a script reference in the head of the HTML document. Then the code would look something like this:

window.onload = funtion() {
window.open('survey/front.php', 'newWindow', 'scrollbars=0,resizable=0,height=490,width=640');

However, note that many browsers have a popup blocker or people may have disabled the ability of scripts to open new or mess with current browser windows. The best most current way is to have kind of an internal popup, i. e. not a new window but a new “layer” appear inside the window on top of the page. There are many prefabricated scripts such as thickbox (http://jquery.com/demo/thickbox/) or multibox (http://phatfusion.net/multibox/) that can be set to pop up automatically after some time, or you can learn how to create such a popup yourself at http://dhtmlpopups.webarticles.org/