By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,693 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

body onload executing after script element?

P: n/a
<body onload="alert('test')">
<script>location = "http://www.google.com"</script>
</body>

....and...

<body onload="alert('test')"></body>
<script>location = "http://www.google.com"</script>

It seems to me as though an alert window containing the word 'test'
ought to appear before the page is redirected to Google yet it isn't.
Any ideas as to why?

Jul 17 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
also, there should be a semicolon after the alert method

alert("BLAH BLAH");

Jul 17 '06 #2

P: n/a
Sevinfooter wrote:
also, there should be a semicolon after the alert method

alert("BLAH BLAH");
That would be "should" in the sense of ; there is no necessity to
insert a semicolon at that point because automatic semicolon insertion
will do it for you, and any instruction to insert such a semicolon
represent no more than a style preference (even if a common one).

Richard.

Jul 17 '06 #3

P: n/a

Richard Cornford wrote:
Sevinfooter wrote:
also, there should be a semicolon after the alert method

alert("BLAH BLAH");

That would be "should" in the sense of ; there is no necessity to
insert a semicolon at that point because automatic semicolon insertion
will do it for you, and any instruction to insert such a semicolon
represent no more than a style preference (even if a common one).

Richard.
All I'm saying, is that it works for me with <body
onload="alert("blah");">

Jul 17 '06 #4

P: n/a
Sevinfooter wrote:
Richard Cornford wrote:
>Sevinfooter wrote:
>>also, there should be a semicolon after the alert method

alert("BLAH BLAH");

That would be "should" in the sense of ; there is no necessity to
insert a semicolon at that point because automatic semicolon
insertion will do it for you, and any instruction to insert such a
semicolon represent no more than a style preference (even if a
common one).

All I'm saying, is that it works for me with
<body onload="alert("blah");">
In what sense "works" (considering that the expected behaviour has been
being exhibited from the outset), and how does that "works" differ from
what happens without the semicolon?

Richard.

Jul 17 '06 #5

P: n/a
About the problem, what I recommend is that you wrap it all in a
function:

<body onload="someFunction();">
<script>
function someFunction() {
alert("your message");
location="http://www.google.com";
}
</script>

Cheers,

Mark

Jul 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.