473,804 Members | 2,104 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 2316
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
7228
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
28578
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
13430
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
7333
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
7069
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
1948
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
2525
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
1846
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
9715
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
10600
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
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
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
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4313
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
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.