View Full Version : On Unload Script
01-12-2010, 05:15 PM
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
01-12-2010, 05:47 PM
(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?"
01-12-2010, 08:33 PM
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?
01-12-2010, 08:48 PM
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.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.