473,796 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<body onload="somethi ng()">

The way the <body onload="somethi ng()"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(s omething())

.... 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 2314
tuxedo wrote :
The way the <body onload="somethi ng()"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(s omething())

... 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.addEvent Listener('load' , dothis, false);
or
window.attachEv ent('load', dothis); // For IE !

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

4/
window.addEvent Listener('load' , function(e)
{
alert('loaded!' );
}, false);
ir
window.attacheE vent('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 addEventListene r.

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 addEventListene r.
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 - addEventListene r - 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 - addEventListene r - 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.attachEv ent('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
7227
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 select="body/size_in_chars"> > 1042"></xsl:when> <xsl:otherwise> SOMETHING HERE THAT I HAVEN'T SORTED OUT YET
2
28577
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 to this problem? thanks!!
9
13426
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"> However, I have found that I can use an alternate file extension, such as <script src="foo.HTML" type="text/javascript"> It works fine with my IE 6 and Mozilla. Will it work with other browsers?
6
7329
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 WinIE6. WinIE6 says there's an error in the code, but the debugging info says the problem is on line 1 char 1, which are comments. <Body bgcolor='black' Text='#dbdbdb' onblur='window.resizeTo(150,150)'
6
7067
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 does not.
16
1947
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 was something like : <?= $myVar; ?> Is this an out dated method? Is it compatible with all versions of PHP (since implementation at least)?
2
2524
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 transparent gif image I can't use LinkButtons over this image. The string that I'm using now is: <body background="BMP/Header.gif" MS_POSITIONING="GridLayout"> Maybe I should use something else in place of GridLayout?
2
2448
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 the client, there is no guarantee that the document has finished loading, and that the DOM is ready to be accessed.
1
1845
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 href="#mid"in ddl event handler? Maybe a Javascript? Please advise. Thanks.
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.