Results 1 to 4 of 4

Thread: On Unload Script

  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile On Unload Script

    Looking for a script when user goes to close the window or re-type in a new address in the address bar --- to open up a seperate small window (like a popup but something that poup blockers will not catch -- offering the user a chance to click there and redirect to another page.

    Thank you in advance

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <body onunload="dothis()">
    (Define dothis() as a function that makes a popup or an alert.)

    Popup blockers are good at what they do, and there is no easy code to get around them-- if there was, then the popup blockers would block it also.
    The only way to (somewhat) reliably get around popup blockers is to use a user's action to trigger the popup, such as a click. If the popup is randomly generated, then it will probably be blocked-- if the user clicks a link (for example) there is a much higher chance it will be allowed to pop up.
    (Note: alerts are never blocked by popup blockers, though they are very annoying.)

    But that's a bad idea, usually, because it will just annoy users. The only time this really makes sense is if there is a current action (like a file upload, or new message available in a chat, etc) that the user might have forgotten about, so it gives them a chance to go back and do something with that.

    If this is just to try to stop potential customers from leaving, then your site will be just another annoying ad-driven website that most people avoid.

    You can decide what makes sense, but if nothing else, use this cautiously, and, please, give it some meaning beyond just "wait, don't leave, you can still buy something!", such as, maybe "there are items in your cart, do you want to leave?"
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default NO desire to annoy clients!

    In fact totally the opposite. Whether they bought what we were selling or not, upon their parting we wanted to offer a free gift.

    And have a small window inviting them to try our service for Free.

    And I would NOT want it to just randomly pop up only upon clicking to close the window or a retype in address bar action - This site will have other links to take them to places to purchase the service also and do not want anything popping up there either - ONLY on closing site.

    That being better clarified how would you write a script for that?

    Thanks

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That is more complex then.
    onunload occurs any time that the page is being "unloaded"-- whenever something else is loaded.

    Since you want it to happen (always) - ([certain times]), then I think the only possibility is to create a script that:
    1. always triggers the function onunload
    2. every link, etc. that you do not want to trigger the event must have a specific command in it, like <a href="next.htm" onclick="skipevent = 1;">
    3. the function for onunload acts only if the variable skipevent is not set.

    You could try the opposite, if you know that only specific links will be "leaving" and you want to trigger the event, but that will not work for just closing the page or typing in the address bar.

    This does not seem very reliable, though, but you can certainly try it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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