473,508 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.js file not loading in time for function call, problem only in Netscape/Mozilla/Firefox

I was under the assumption that javascript loads all the <head></head>
elements before processing the <body> tag in Mozilla/Netscape/Firefox.
It doesn't seem like it, with my problem.

I have navigation that has onMouseOver and onMouseOut triggers, that
use function calls in my external .js file. When I mouseOver a button
in my navigation quickly enough to catch it before the rest of the body
loads, it returns a function "not defined" error. The function is
definitely defined in my .js file. If I wait for the whole page to
load, and try mousing over and out of my nav, I don't get that error.

I don't have this problem with IE.
Any help would be much appreciated.
Danny

Jul 23 '05 #1
5 2762


da*********@gmail.com wrote:
I was under the assumption that javascript loads all the <head></head>
elements before processing the <body> tag in Mozilla/Netscape/Firefox.
It doesn't seem like it, with my problem.

I have navigation that has onMouseOver and onMouseOut triggers, that
use function calls in my external .js file. When I mouseOver a button
in my navigation quickly enough to catch it before the rest of the body
loads, it returns a function "not defined" error. The function is
definitely defined in my .js file. If I wait for the whole page to
load, and try mousing over and out of my nav, I don't get that error.


URL? And if it has lots of content describe what your navigation buttons
are.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
This is definately a problem in these browsers that has been
long known esp. in Netscape

The only solution that may be any use to you is:

define/attach your external .js file in the <head></head> as
normal then the rest of your page as normal...

then near the bottom just before the </html> end tag try:

<script language="javascript" type="text/javascript">
functionToCall();</script>

This gives your page a chance to load the JS before calling the
routine... You could also try:

<body onLoad="javascript:functionToCall();">

which theorically waits till all is loaded

Hope this helps...

Regards

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 23 '05 #3
Sorry, just re-read your question and my answer probably aint much
help... Apologies

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 23 '05 #4
<da*********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I was under the assumption that javascript loads all the <head></head>
elements before processing the <body> tag in Mozilla/Netscape/Firefox.
It doesn't seem like it, with my problem.


The contents of the <head></head> are processed, it does not mean that
the external script file referred to by <script type="text/javascript"
src="yourfile.js"></script> has been downloaded and parsed before the
<body> is rendered. These events happen asynchronously, yourfile.js can
be downloading while the <body> is being rendered.

As a result, you need to do something to test before dispatching to the
function defined in the external file.

<head>
<script type="text/javascript" src="yourfile.js"></script>
<script type="text/javascript">
function safeRedirector(f, args) {
if ('undefined' == typeof f) {
alert('The code needed to support that is not yet loaded');
} else {
f(args);
}
}
</script>
</head>
<body>
<a href="..."

onmouseover="safeRedirector(yourMouseOverFunctionD efinedInYourFileDotJs,
[ arg1, arg2, arg3 ]);">Link</a>

Or maybe:

<head>
<script type="text/javascript" src="yourfile.js"></script>
<script type="text/javascript">
var bodyLoaded = false;
function safeRedirector(f, args) {
if (bodyLoaded) {
f(args);
} else {
alert('The code needed to support that is not yet loaded');
}
}
</script>
</head>
<body onload="bodyLoaded = true;">
<a href="..."

onmouseover="safeRedirector(yourMouseOverFunctionD efinedInYourFileDotJs,
[ arg1, arg2, arg3 ]);">Link</a>

You can set up safeRedirector() to be a little more transparent
(actually passing parameters instead of requiring they be part of an
array) I just didn't have the time to write all that.

The other thing to do is not have a single generic redirector, but to
have 'stub' functions for each of your main handlers that dispatches to
it if it's available.

Lastly, you could not define your events in the HTML, but instead attach
them to the elements dynamically. Define the function in your external
js file:

function setAllHrefMOut(f, d, inLayer) {
if (!inLayer) {
d = document;
}

if (d) {

var i;

if (d.links) {
i = d.links.length;
while (i-- > 0) {
if (!d.links[i].onmouseout) {
d.links[i].onmouseout = f;
}
}
}

if (d.layers) {
i = d.layers.length;
while (i-- > 0) {
setAllHrefMOut(f, d.layers[i].document, true);
}
}
}
} // setAllHrefMOut()

Then call it -onload-:

<body onload="setAllHrefMOut(someFunction);">

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #5
da*********@gmail.com wrote:
I was under the assumption that javascript loads all the <head></head>
elements before processing the <body> tag in Mozilla/Netscape/Firefox.
It doesn't seem like it, with my problem.

I have navigation that has onMouseOver and onMouseOut triggers, that
use function calls in my external .js file. When I mouseOver a button
in my navigation quickly enough to catch it before the rest of the body
loads, it returns a function "not defined" error. The function is
definitely defined in my .js file. If I wait for the whole page to
load, and try mousing over and out of my nav, I don't get that error.

I don't have this problem with IE.
Any help would be much appreciated.


You could specify that your <body> has a CSS attribute visibility:hidden.

Then the last line of your script file could overturn that. That way
there is nothing visible to mouseover during loading of the script.

Jul 23 '05 #6

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

Similar topics

1
8067
by: Troy | last post by:
Hi! I am working on a rather complicated set of html and javascript files here and am experiencing some serious IE/Netscape(Mozilla actually) incompatability issues. I have an html page that...
3
8423
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place...
9
9336
by: Ian Richardson | last post by:
If I follow the steps on http://www.dhtmlcentral.com/tutorials/tutorials.asp?id=11 to add .js files to a document on demand, let's say by <body onload="blah();">, how can I reliably tell that it...
1
1990
by: Charlie T | last post by:
hello, I need a little guidance here... I am tring to parse out an XML file, but with some restrictions. here is my XML FILE: ---------XML----------- <XML> <Cam name="01">...
4
3619
by: Thomas Mlynarczyk | last post by:
Hi, I stumbled over a strange behaviour of Mozilla. When I want to access the caller property of a function that was not called from within another function, Mozilla seems to abort the script....
13
1535
by: M B HONG 20 | last post by:
Hi all - I have a .NET web service running on a remote machine, and I have Netscape Navigator 7.0 accessing it through javascript on the client side through SOAP javascript coding. Everything...
41
2498
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
2
9536
by: Alex | last post by:
Yes you can: <html><head><script language="javascript"> SaveToFile('This is a text to save in a file', 'C:\\temp\\test.txt'); alert(read('C:\\temp\\test.txt')); function SaveToFile (text,...
4
3838
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
0
7224
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,...
0
7120
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...
0
7323
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,...
0
7380
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...
0
4706
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...
0
3192
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
0
415
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...

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.