/    Sign up×
Community /Pin to ProfileBookmark

body onLoad and body unLoad on same page??

is it posible to make a body onLoad and a body Unload on the same page?

[code]
<body onLoad=”do_count();” unLoad=”Auto Surf 4 Euros ALERT!nThis page is breaking our frames!nThis will trough you out of the surfuse the CANCEL button and the use the button:Abuse reportnnIf you are leaving the surf normaly then press OK”; class=bar bgcolor=”#CADDEB”>
[/code]

this do not work!!!

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guySep 05.2005 — yes its possible. but its onload onunload
Copy linkTweet thisAlerts:
@felgallSep 05.2005 — Why do you have in front of each " ?

Also the content of your onunload is text and not a Javascript command.
Copy linkTweet thisAlerts:
@KravvitzSep 05.2005 — He's probably got that inside a PHP echo statement.

Do any PHP novices ever read the documentation? You don't have to use echo all of the time.
Copy linkTweet thisAlerts:
@UltimaterSep 05.2005 — Try the [color=royalblue]onbeforeunload[/color] event and removing all your extra semicolons.
Copy linkTweet thisAlerts:
@UltimaterSep 05.2005 — This will trough you out of the surfuse the CANCEL button and the use the button[/quote]
Note that the backslash in the above code is [i]very[/i] dangerous. turn that backslash into a n not a u.

Here's some code to get you started (note it only works in IE)
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 STRICT//EN" "http://www.w3.org/TR/HTML401/strict.dtd"&gt;
&lt;html dir="ltr" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;title&gt;example&lt;/title&gt;
&lt;script type="text/javascript"&gt;
function closeIt()
{
event.returnValue = "Auto Surf 4 Euros ALERT!nThis page is breaking our frames!nThis will trough you out of the surfnuse the CANCEL button and the use the button:Abuse reportnnIf you are leaving the surf normaly then press OK";

}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onbeforeunload="closeIt()"&gt;
&lt;p&gt;Navigate to another page to fire the before unload event.
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@reverentxauthorSep 06.2005 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 STRICT//EN" "http://www.w3.org/TR/HTML401/strict.dtd"&gt;
&lt;html dir="ltr" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;title&gt;example&lt;/title&gt;
&lt;script type="text/javascript"&gt;
function closeIt()
{
event.returnValue = "Auto Surf 4 Euros ALERT!nThis page is breaking our frames!nThis will trough you out of the surfnuse the CANCEL button and the use the button:Abuse reportnnIf you are leaving the surf normaly then press OK";

}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onbeforeunload="closeIt()"&gt;
&lt;p&gt;Navigate to another page to fire the before unload event.
&lt;/body&gt;
&lt;/html&gt;


the problem is that i need 2 thing to happens

a BODY onLoad event

an a BODY unload event

<i>
</i>&lt;body onLoad="do_count();";
&lt;body unLoad="Auto Surf 4 Euros ALERT!nThis page is breaking our frames!nThis will trough you out of the surfnuse the CANCEL button and the use the button:Abuse reportnnIf you are leaving the surf normaly then press OK"; class=bar bgcolor="#CADDEB"&gt;

the body onLoad does a count() script

and the unLoad event is fired on closing of the page

my problem is I have 2 body tags to fire..

but only on available ?
Copy linkTweet thisAlerts:
@rigadonSep 06.2005 — Erm - as bathurst_guy and felgall said above it's [B]onunload[/B] NOT unload and you should have [B]javascript[/B] in the tags not just plain text:

[CODE]<html>
<head>
<title>test</title>
<link rel=stylesheet href="main.css" type="text/css">
</head>
<body onload="alert('loaded');" onunload="alert('unloaded');">
test
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@felgallSep 06.2005 — You can also code it as pure Javascript:

<i>
</i>function load() {
alert('loaded');
}
function unload() {
alert('unloaded');
}
window.onload = load;
window.onunload = unload;


Then substutite whatever you want to run into the load and unload functions.
×

Success!

Help @reverentx 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 6.1,
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,
)...