473,383 Members | 1,789 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,383 software developers and data experts.

<body onload="something()">

The way the <body onload="something()"works ensures that the complete html
document is loaded before something() is executed.

Can the same be achieved when placing the onload call in document somewhere
except within the body tag, or must it always be in the body tag?

For example, if this is placed elsewhere ...

window.onload(something())

.... it will run before the full document has loaded, so that does not work.

Is it possible to refer to the window only when loaded in any other way?

Dec 9 '06 #1
5 2272
tuxedo wrote :
The way the <body onload="something()"works ensures that the complete html
document is loaded before something() is executed.

Can the same be achieved when placing the onload call in document somewhere
except within the body tag, or must it always be in the body tag?

For example, if this is placed elsewhere ...

window.onload(something())

... it will run before the full document has loaded, so that does not work.

Is it possible to refer to the window only when loaded in any other way?
function dothis(e)
{
alert('loaded!');
}

1/
window.onload = dothis;

2/
window.addEventListener('load', dothis, false);
or
window.attachEvent('load', dothis); // For IE !

3/
window.onload = function(e)
{
alert('loaded!');
}

4/
window.addEventListener('load', function(e)
{
alert('loaded!');
}, false);
ir
window.attacheEvent('load', function(e)
{
alert('loaded!');
}); // for IE !

Hope this helps you ;)

--
Naixn
http://fma-fr.net
Dec 9 '06 #2
naixn wrote:
Hope this helps you ;)
[...]

Thank you the function runs after the page has loaded, and it certainly
helps!

As much as I dislike browser specific code, I understand that I should make
attachEvent run only on IE, and that I can safely make any other browser
run addEventListener.

Dec 9 '06 #3
tuxedo wrote:
naixn wrote:
>Hope this helps you ;)

[...]

Thank you the function runs after the page has loaded,
and it certainly helps!

As much as I dislike browser specific code, I understand
that I should make attachEvent run only on IE, and that I
can safely make any other browser run addEventListener.
Neither of those statements are true. The - attachEvent - method is
supported (at least on some objects) by browsers other than IE, such as
Opera versions 7. The - addEventListener - method can only be used on
browsers that support it, which is certainly most of the modern ones but
by no means all. There is also no formal requirement for the window
object to support - addEventListener - as it is specified as a method of
Nodes, and the window object is not a node.

Richard.
Dec 9 '06 #4
naixn wrote:
<snip>
or
window.attachEvent('load', dothis); // For IE !
<snip>

IE will be happier if the first argument is "onload" rather than "load".

Richard.
Dec 9 '06 #5
Richard Cornford wrote:

[...]

Thanks. On second thoughts, I think I'll leave this method out in exchange
of simply moving the function call below the required loaded elements.

Dec 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rupa | last post by:
Hi, I'm trying to write an xslt to convert an email in xml format to a new xml format. <descr> <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select> <xsl:when test=" <xsl:value-of...
2
by: Matt | last post by:
If I do the following, the browse text box still cannot see C:/hello world/test.txt. <input type="file" name="fileName" value="C:/hello world/test.txt" size=80> Any ideas? and workarounds...
9
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript">...
6
by: rob | last post by:
Hi I'm trying to create a "roll-up" effect when a window loses focus and then "roll-down" when it regains focus. This statement works properly with every browser I can get my hands on EXCEPT...
6
by: Mason A. Clark | last post by:
LAST WORD(s): 1. MSIE6 and Firefox will go to the top of the page on command <a href="#top">go upsy</a> even if there is NO name="top" or id="top" They know what a "top" is :-) Opera...
16
by: rik | last post by:
I was flicking through a PHP book (one of the teach in 24 hour ones) and I came across something I had never seen before in PHP. It was a method of printing out without using the print method, it...
2
by: Just D. | last post by:
Who knows what should we include into aspx file to show some image as a background picture but only once at the top of the page? I don't want to add the Image control because even if it uses a...
2
by: cmay | last post by:
I have recently been working with RegisterStartScript in my asp.net pages. However, as you probably know it places the script at the end of the FORM tag. However, when this code executes on...
1
by: =?Utf-8?B?Sm9obg==?= | last post by:
I have a dropdownlist in masterpage and a big table in contentpage. When ddl selection changes, I want to move a specific row of the table to the top of the contentpage. Can I do something like <a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.