Results 1 to 3 of 3

Thread: window open problem

  1. #1
    Join Date
    Jun 2012

    window open problem

    Hello together,

    it was a few years since I used javascript, but for a study i need to use a javascript function, which opens a new window to launch questions for the users, who leave the homepage. So I tried again with some coding...

    When this function is called on unload, the alert (to test the function) pops up, but the window doesn't - both with IE and FF (although in IE it works locally on my computer ):

    FF tells me "winout is null winout.focus();"

    Here's the code from js-File:

    var winout = null;

    var exit=0;
    var w = 300;
    var h = 200;
    var qpage_user = "http://www.xyQuestions1.de";
    var qpage_no_user = "http://www.yzQuestions2.de";
    var pagename = "Befragung";
    var q_settings = 'height=' + h + ',';
    q_settings += 'width=' + w + ',';

    function nouser (exit) {
    pagename = "Befragung_no_User";
    if (exit == 1 && user != "yes") // user is defined later
    if(winout == null)
    winout = window.open(qpage_no_user,pagename,q_settings);



    and HTML page:

    <body onunload="nouser(1)">

    Thanks in advance.


  2. #2
    Join Date
    Feb 2003
    Michigan, USA
    If the user has pop ups blocked, the window.open function can return a null value. Browsers generally only open windows as a result of a user generated event, such as a click. If you try opening a new window using window.open on page load, and the user is blocking pop ups, the window.open function returns a null value. You'll need to guard against this.

  3. #3
    Join Date
    Jul 2008
    urbana, il
    thankfully, you cannot launch a popup from an onunload event; that would be annoying!
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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