/    Sign up×
Community /Pin to ProfileBookmark

Help with onunload

I keep having an issue with onunload. I’m trying to get an alert message to pop up when either the window or the tab is closed, but whenever I click to a defferent page within my website, it is considered to have closed the current page, so it triggers the alert.

Here is the first body tag:

[code=html]<body onunload=”alert(‘Thanks for visiting Pierce County Customs!’)” bottommargin=”0″ leftmargin=”0″ marginheight=”0″ marginwidth=”0″ rightmargin=”0″ topmargin=”0″ background=”background.jpg” text=”#EAF5FF”>[/code]

I thought this was supposed to work, any help would be appreciated greatly.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@justinbarneskinAug 27.2009 — You'll need to run an [B]if[/B] statement to check the domain.

Personally, I would hate you if I ever came across your alert.

alerts are for developers and diagnosing code, not for slapping your

visitors. Its almost as bad as enbeded music that starts auto with no player controls.
Copy linkTweet thisAlerts:
@gshaver2006authorAug 27.2009 — Truthfully, I would never do this on a real website, but I need javascript in my code for an assignment, and I thought this would be an interesting thing to stick in there. I would slit my own throat before implementing this on a real website.

~G
Copy linkTweet thisAlerts:
@Sterling_IsfineAug 27.2009 — I keep having an issue with onunload. I'm trying to get an alert message to pop up when either the window or the tab is closed, but whenever I click to a defferent page within my website, it is considered to have closed the current page, so it triggers the alert.
[/QUOTE]


Every internal link could have an onclick handler like this:

[CODE]<a href='somepage.php' onclick='document.body.onunload=null'>xxxxxxx</a>[/CODE]This could be assigned to all relevant links in a loop.
×

Success!

Help @gshaver2006 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...