473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

body onload executing after script element?

<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
5 1632
also, there should be a semicolon after the alert method

alert("BLAH BLAH");

Jul 17 '06 #2
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mica Cooper | last post by:
Trying to set the focus to an element of input type on loading the page. This is the code I used but it doesn't work. Any suggestions? (IE 6, Windows) <SCRIPT language=JavaScript> funcion...
2
by: Starry Gordon | last post by:
I've been running some small test programs which seem to indicate something noticed in a larger script, that a function called from onLoad() in the <body> tag will not succeed in creating a window...
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
2
by: Brian | last post by:
Hi all. I have a bunch of pages that reference an external script from the head section. I'd like to add additional <script> elements to the pages' bodies, but I can't edit the pages...
10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
5
by: Patient Guy | last post by:
I have this in a document: <body onload="a_function(this);"> In an (external) script file, I define a_function() as follows: function a_function(obj) { // surprise errant coding here
2
by: Joy | last post by:
Hi all I know that I can use the following code to add some script-code to a button button.Attributes("onclick") = myscript I like to do the same for the page itself as ("onload") =...
6
by: maria.iglesias.19 | last post by:
Hya, Is it possible to have onload events on elements other than the body tag ? Thanks in advance, Maria
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.