473,614 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing code before page load complete...

Problem in short: user is moving (clicking a link) from my page before some
JS code is run (to write a cookie).

The code does not run (in Body's onLoad event) until the page loads as there
are a number of images which can take a while to load on a slow connection.
Using fewer/different graphics is not an option!

The code writing a cookie the is called in the Body's onLoad event:

<body onLoad="setLast ();">

The code setting up the cookie is in a function in the Head section

function setLast() {
var myPage = location.href;
//remove old value
deleteCookie('l astPage');
var expDate = new Date();
expDate.setTime ( expDate.getTime () + ( myDuration * 60 * 60 * 1000 ) );
setCookie('last Page', myPage,expDate, cookiePath);
}
....and it calls setCookie utility code in an external JS file also called in
the Head section:

<script src="../support/settings.js" language="JavaS cript"
type="text/JavaScript"></script>

If I take the cookie setting code out of it's function wrapper but still in
the Head's <script> section will it execute as soon as it can? Or, would it
be wiser to put it inline in the Body's content in a <script> tag?
Presumably the Body onLoad checks for the external JS as well as the images,
whereas run-on-load might cause the code to execute before the external JS
was available and cause the code to fail?

I'd welcome knowledge from those who understand this rather than just reply
on some local testing and doubtless create a whole different problem

Regards

Mark

Jul 20 '05 #1
2 29804
"Mark Anderson" <ma**@notmeyear dley.demon.co.u k> writes:
If I take the cookie setting code out of it's function wrapper but still in
the Head's <script> section will it execute as soon as it can?
It should. As soon as it can is after all previous scripts have been
executed.
Or, would it be wiser to put it inline in the Body's content in a
<script> tag? Presumably the Body onLoad checks for the external JS
as well as the images, whereas run-on-load might cause the code to
execute before the external JS was available and cause the code to
fail?


It shouldn't.

If you have more than one script tag, it won't execute the second before
the first have loaded. The second could depend on functions from the first,
and the first could contain document.write' s that completely change
how the rest of the document is parsed.

I did hear of a problem with Netscape 6 where this didn't happen. The
scripts were loaded asynchroneously . The only solution for that
appeared to be to not rely on external scripts before the onload event
was triggered.

Netscape 6 was a very buggy browser.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Thanks. I'll try the code in the Head outside a function wrapper.

Luckily (?) for me the supported spec is for IE. I'm not deliberately
IE-centric but if there are Netscape, etc. issues in this particular
project the code will be passed on to somebody else's to play with in
slowtime. Not, I hasten to add that I'd want that.

Regards

Mark
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:wu******** **@hotpop.com.. .
"Mark Anderson" <ma**@notmeyear dley.demon.co.u k> writes:
If I take the cookie setting code out of it's function wrapper but still in the Head's <script> section will it execute as soon as it can?
It should. As soon as it can is after all previous scripts have been
executed.
Or, would it be wiser to put it inline in the Body's content in a
<script> tag? Presumably the Body onLoad checks for the external JS
as well as the images, whereas run-on-load might cause the code to
execute before the external JS was available and cause the code to
fail?


It shouldn't.

If you have more than one script tag, it won't execute the second before
the first have loaded. The second could depend on functions from the

first, and the first could contain document.write' s that completely change
how the rest of the document is parsed.

I did hear of a problem with Netscape 6 where this didn't happen. The
scripts were loaded asynchroneously . The only solution for that
appeared to be to not rely on external scripts before the onload event
was triggered.

Netscape 6 was a very buggy browser.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3

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

Similar topics

13
2836
by: BK | last post by:
Can someone point me to a code sample that illustrates executing long running tasks (asynchronous) from a web application in ASP.NET? I assume that Web Services might come into play at some point, but I'm not sure how to get started. For example, I have an application that, upon a user initiating through a button or link click, will go out and generate a bunch of files (this could take several minutes). This will happen in batches, so I...
4
12666
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck Gatto Dan Guzman Apr 27 2000, 12:00 am show options
2
1746
by: mart | last post by:
I am experiencing a weird problem with some buttons on my webpage. The page_load is executing twice when a button is clicked. If I replace the button for a Linkbutton the page_load only loads once. I've set the Autoeventwireup to false. Could it be a framework problem ? On other computers the
7
5231
by: Jibey | last post by:
Hello: I'm facing a very strange problem. When I run my Web application in Visual Studio.NET the Page_Load event is not executing. Other events like a Button_Click are executing. It doesn't matter whether I'm running the application in VS.NET or browsing it using http://localhost/... the Page_Load event is not executing under either conditions. I've determined that this problem occurs in both VB.NET and VC#.NET. The Page_Load event...
11
1451
by: simon | last post by:
Hello, I'm helping write a .net app, we are using VS2005 and asp/vb.net for code we are using the "masterPage.master" technique, within the masterpage we have an asp:contentplaceholder that is the place holder for the main portion of the body of the site my question is, is there a way to test what aspx page will be loaded into the contentplaceholder? basically if it is our home page, that page has a wider definition than all of our...
7
2805
by: tshad | last post by:
I thought I understood how the SaveViewState is working and was trying to use this (as per some code I found) to detect refreshes. It seemed to be working but I found that the SaveViewState was executing twice on load of page and can't figure out why. I was writing out to a text file in the SaveViewState event and it was writing it twice everytime a page was loaded (whether on an initial load of the page or Postback). I took out the...
8
2486
by: dd | last post by:
Has anyone found a way around the problem IE has if you create elements (script or div, doesn't seem to matter) BEFORE the document.readyState is "complete" ? I know you can sometimes get away with only waiting for "interactive" state, but I've found that on some pages, that can result in a weird error with a dialog box along the lines of "Internet operation aborted error" (or something like that, I haven't seen it for a long time since...
14
23141
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So, we're looking for a way to display the page with a "please wait..." message while the process is running, and then, when the process is done, update the page with the actual results/page content. We have a page that opens another browser/page...
13
2506
by: mowsen | last post by:
Hello Group, i'm using a little "ajax" loader script to dynamically load files into different "div" tags on my main site. the code for this part looks like: function loader() { var args = loader.arguments; switch (args) { case
0
8197
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
8142
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
8640
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
8589
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...
0
8443
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
6093
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
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
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
0
1438
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.