Connecting Tech Pros Worldwide Help | Site Map

body onload executing after script element?

yawnmoth
Guest
 
Posts: n/a
#1: Jul 17 '06
<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?

Sevinfooter
Guest
 
Posts: n/a
#2: Jul 17 '06

re: body onload executing after script element?


also, there should be a semicolon after the alert method

alert("BLAH BLAH");

Richard Cornford
Guest
 
Posts: n/a
#3: Jul 17 '06

re: body onload executing after script element?


Sevinfooter wrote:
Quote:
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.

Sevinfooter
Guest
 
Posts: n/a
#4: Jul 17 '06

re: body onload executing after script element?



Richard Cornford wrote:
Quote:
Sevinfooter wrote:
Quote:
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");">

Richard Cornford
Guest
 
Posts: n/a
#5: Jul 17 '06

re: body onload executing after script element?


Sevinfooter wrote:
Quote:
Richard Cornford wrote:
Quote:
>Sevinfooter wrote:
Quote:
>>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.

Sevinfooter
Guest
 
Posts: n/a
#6: Jul 17 '06

re: body onload executing after script element?


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

Closed Thread