body onload executing after script element?

Y

yawnmoth

<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?
 
L

Lee

yawnmoth said:
<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?

Why would you expect that? In-line script is executed as the page
is loading. The onload method executes after it has loaded.


--
 
R

Richard Cornford

Sevinfooter said:
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.
 
S

Sevinfooter

Richard said:
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");">
 
R

Richard Cornford

Sevinfooter said:
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.
 
S

Sevinfooter

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
 
L

Lee

Sevinfooter said:
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>

That doesn't seem to be what the OP was trying to do.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top