473,785 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do something BEFORE window.onload?

I have a working script but it gets executed first after the
page has finished loading all the images (which may take a
while). Since the script is placed in window.onload i
understand it has to wait for the loading to get done.

However, i wish to execute the script BEFORE all the
images had time to get loaded. Is that doable? How?

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #1
16 10150
VK
> Is that doable?
It depends on what is your script doing. If it addresses any page
elements, it will be a dice game (50/50 the requested element is
rendered or not).
How?

Just insert your script at the point you want to start the execution.

<body>
......
<script type="text/javascript">
// your script
</script>
....

Jul 23 '05 #2
>> Is that doable?
It depends on what is your script doing. If it addresses any page
elements, it will be a dice game (50/50 the requested element is
rendered or not).
How?

Just insert your script at the point you want to start the
execution.

<body>
.....
<script type="text/javascript">
// your script
</script>
...

The thing is that i never execute the code. It is put in the
function "window.onl oad" and placed in the head of the
document. BUT the code is not executed "onload" as in
"as we get to the page" - it's more "onload" as in "when
we have finished downloading the whole thing".

The loading time is of importance here since the browser
loads about 100 images. I wish to do a thing BEFORE all
the images have been loaded.

Did i make myself more clear or confused even more? :)

Here's an example. Try to scroll a bit, exit, then come
back again to the page and you'll be automatically scrolled
to the position you were at when you left.

The issue is that you have to wait until all the images has
been loaded, which takes a while.
http://www.viltersten.com/sve/files/elvis.htm

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #3
I think that your problem is loading the external images. It takes too
much time to load all the images from another site and its still
loading :)

You can load the images after loading the page with XMLHttpRequest( )...
that you will execute your script after loading the page.

Jul 23 '05 #4
On 03/06/2005 11:30, Konrad Viltersten wrote:

[snip]
[...] the code is not executed "onload" as in "as we get
to the page" - it's more "onload" as in "when we have
finished downloading the whole thing".
That's generally how the load event is interpreted.
The loading time is of importance here since the browser
loads about 100 images. I wish to do a thing BEFORE all
the images have been loaded.


Then include the SCRIPT element as the last child of the BODY element.
The script will be parsed and executed more-or-less when the entire
document has been loaded, irrespective of whether the images have been
downloaded.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
>> The loading time is of importance here since the browser
loads about 100 images. I wish to do a thing BEFORE all
the images have been loaded.


Then include the SCRIPT element as the last child of the BODY
element. The script will be parsed and executed more-or-less when
the entire document has been loaded, irrespective of whether the
images have been downloaded.

Hmmm... I simply didn't think of it. I'll try that and we'll
see what will happen.

Thanks to both of you, guys.

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Jul 23 '05 #6
Konrad Viltersten wrote:
Is that doable?

It depends on what is your script doing. If it addresses any page
elements, it will be a dice game (50/50 the requested element is
rendered or not).
How?

Just insert your script at the point you want to start the
execution.

<body>
.....
<script type="text/javascript">
// your script
</script>
...

The thing is that i never execute the code. It is put in the
function "window.onl oad" and placed in the head of the
document. BUT the code is not executed "onload" as in
"as we get to the page" - it's more "onload" as in "when
we have finished downloading the whole thing".


I think what VK was saying here is essentially valid:
Since you want the code executed after the HTML has been loaded, but
not necessarily waiting for all referenced objects to be loaded (i.e.
pictures, sounds), just put the code at the bottom of the document.

</body>
<script> ... </script>
</html>

And don't use onLoad -- just execute the code yourself, within that
<script /> element.

Jul 23 '05 #7
Random wrote:
<snip>
... , just put the code at the bottom of the document.

</body>
<script> ... </script>
</html>

<snip>

More predictable results would likely be achieved by avoiding a
dependency on browser error-correction, so using valid HTML:-

<script type="text/javascript"> ... </script>
</body>
</html>

Where the script element has the required type attribute and appears in
a context in which script elements are allowed.

Richard.
Jul 23 '05 #8
Richard Cornford wrote:
Random wrote:
<snip>
... , just put the code at the bottom of the document.

</body>
<script> ... </script>
</html>

<snip>

More predictable results would likely be achieved by avoiding a
dependency on browser error-correction, so using valid HTML:-

<script type="text/javascript"> ... </script>
</body>
</html>

Where the script element has the required type attribute and appears in
a context in which script elements are allowed.

Richard.


Intended to relate the basic idea only. You'll notice it was very
clearly a fragment. As well, if someone grabs code from anywhere and
doesn't adapt it to his own needs / desires, he's making his own bed,
no?

I shouldn't have posted at all, but Google Groups didn't show me the
two preceding posts until I'd already posted mine. Surprise surprise.

Jul 23 '05 #9
Random wrote:
Konrad Viltersten wrote:
> Is that doable?
It depends on what is your script doing. If it addresses any page
elements, it will be a dice game (50/50 the requested element is
rendered or not).

> How?
Just insert your script at the point you want to start the
execution.

<body>
.....
<script type="text/javascript">
// your script
</script>
...

The thing is that i never execute the code. It is put in the
function "window.onl oad" and placed in the head of the
document. BUT the code is not executed "onload" as in
"as we get to the page" - it's more "onload" as in "when
we have finished downloading the whole thing".


I think what VK was saying here is essentially valid:
Since you want the code executed after the HTML has been loaded, but
not necessarily waiting for all referenced objects to be loaded (i.e.
pictures, sounds), just put the code at the bottom of the document.

</body>
<script> ... </script>
</html>

And don't use onLoad -- just execute the code yourself, within that
<script /> element.

For God's sake, Google Groups sucks... it didn't show me the two posts
that basically resolved this one.

Sorry about that.

Jul 23 '05 #10

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

Similar topics

6
4578
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way to tell if the window.onload event has already fired. I cannot edit the onload event handler itself, and my function can only exist in an external js file, sourced from the document's head section. Any ideas?
2
4604
by: Jenny | last post by:
In the code below, I can write html content var t='<body BGCOLOR=blue>' for a new window. But if it contains javascript, such as var t='<body onload="window.open('new1.html')">', this code will not work. Could you confirm this and find such syntax rule for me on the internet? Thank a lot. <html><head> </head><body> <SCRIPT language=JavaScript>
4
2871
by: jadiyo | last post by:
Hi, I've read many questions about how to automatically open a new window from a page using the JavaScript onLoad command. Unfortunately, due to the web application framework being used (WebLogic Portal 7), I can not use it as it is already being used and is only called once by the browser(so I believe). What I am essentially trying to do is open a "Please wait, this may
3
10203
by: Liming | last post by:
Hi, Here is my situation. I have a textarea on the page. When the page loads, I need it to have some default text (which will be generated dynamically) so I did something like this function init() {
3
1800
by: Frances | last post by:
I have three functions I need triggered when page loads, so have <body onload="function1();function2();function3()"> but I want to take all these function calls out of body tag and call them in header, thus: window.onload=function1;function2; but I just realized that only first function in this list gets called
5
2313
by: tuxedo | last post by:
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())
6
19320
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I know, this shouldn't be an issue, but I just can't get it to work. The script only needs to work with Firefox/Mozilla, so XP code isn't an issue. I have tried to open a window like so.
20
11913
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for (i=0;i<obj.length;i++) { obj.attachEvent('ondrag', noDrag); }
5
9485
by: lilOlMe | last post by:
Hi there! I'm developing some crazy Tab Control in .NET that uses JavaScript. A particular JavaScript method needs to be called during the window.onload event in order to initialize my Tab Control. The thing is that there can be more than one Tab Control on the page....and each one must be initialized during the window.onload event. Adding the JavaScript function call responsible for initializing a particular Tab Control to the...
2
2243
by: Beni Rose | last post by:
I'm trying to open a new window using window.open and then print that window once it's loaded. It works fine in Firefox, but not at all in IE. No matter what I put in my onload, it gets ignored. Here's the code: function openPrintPage(loc) { var printWin = window.open(loc+'? dl=false','printpage','width=600,height=800,location=no,menubar=no,directories=no,status=no,toolbar=no,scrollbars=yes,resizable=yes'); printWin.onload = function()
0
9645
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
9481
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
10155
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
10095
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,...
0
9954
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...
1
7502
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
5383
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...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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.