M
Mark Anderson
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('lastPage');
var expDate = new Date();
expDate.setTime( expDate.getTime() + ( myDuration * 60 * 60 * 1000 ) );
setCookie('lastPage', 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="JavaScript"
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
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('lastPage');
var expDate = new Date();
expDate.setTime( expDate.getTime() + ( myDuration * 60 * 60 * 1000 ) );
setCookie('lastPage', 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="JavaScript"
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