Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Thanked 3 Times in 3 Posts

    Launch a window on pop-up?


    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

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Halle (Saale), Germany
    Thanked 1,052 Times in 1,025 Posts
    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) 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 or 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/


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts