/    Sign up×
Community /Pin to ProfileBookmark

An alternative to using onUnload for a pop-up

I’m working on an application where the client requires us to pop-up a survey page when the user leaves their website (either by going to another page or closing the browser).
The developers before me had used the onUnload event in the <body> tag to do this:

<head>
<script language=”JavaScript”>
function openSurvey()
{
window.open(“http://www.someURL.com“);
}
</script>
</head>

<body … onUnload=”openSurvey()”>

I’ve been told not to use onUnload to do this and for whatever reason it seems this only works in IE. My test page in NS 7, 8 and Firefox all fail to display the pop-up window.

What’s the appropriate way to do something like this that’s cross-browser compatible.

Thanks
Curt

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CytaelJan 30.2006 — there is not an appropriate way to do this.

the assumption is that when a user leaves your page, they're done with it. to attempt to force them back to any portion of your site is generally undesired behaviour and is not supported by any decent web browsers.

onUnload works in IE, because IE is crappy. There are no other options.

Why not just stick a link on the bottom of the page somewhere inviting willing users to take your survey?
Copy linkTweet thisAlerts:
@ccrandall77authorJan 30.2006 — While I agree that a pop-up survey is not something I'd want to deal with, our client wants this. If there isn't anyway to do it in a non-IE browser, then I guess they'll have to live with it.
×

Success!

Help @ccrandall77 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...