pop up new window if user is closing the main window

Discussion in 'JavaScript' started by toyotaMAN, Sep 10, 2007.

  1. #1
    Im needing a script that when a user clicks the "X" (closing the window) a new small pop up window will appear

    The new window will ask "Why are you abandoning my site?" and then offer a new price... then submit message or totally close the new window and main window..

    thanks..
     
    toyotaMAN, Sep 10, 2007 IP
  2. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    The onunload (or in some browsers, onbeforeunload) event will help you.
     
    Synchronium, Sep 10, 2007 IP
  3. toyotaMAN

    toyotaMAN Peon

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the problem is , if the user is browsing on my site and then go to my other links or web pages the onunload will trigger .. I want only if the user totally exits to my website or click "X"
     
    toyotaMAN, Sep 10, 2007 IP
  4. magnon

    magnon Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if (window.XMLHttpRequest){ window.opener = window;
    var win = window.open(location.href,"_self");
    win.close(); }
    else if (window.ActiveXObject) { window.opener = ""; window.close(); }

    try this code
     
    magnon, Feb 12, 2008 IP