Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linked js files 1

Status
Not open for further replies.

CharlieChalk

Programmer
Feb 5, 2003
10
0
0
GB
Hi

I'm trying to link a js file to my HTML page using <script language=&quot;JavaScript&quot; src=&quot;/script.js&quot; /JavaScript&quot;></script>
but don't seem to have any luck.

Once I remove the javascript from the HTML page, leaving the above link, and I view the page in IE6 I get &quot;errors on page&quot;. the error message won't stay on the screen as the page seems to constantly be refreshing (?) and removing the message.

I'm sure its something realy stupid that I'm doing wrong, but any help would be greatly appreciated.
 
Try this:

Code:
<script src=&quot;script.js&quot; type=&quot;text/javascript&quot;></script>

Cheers,

Edward &quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
yea, I agree....whats with the slashes???
&quot;Why is it always the quiet ones?&quot;

Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
AIM & MSN: robacarp
 
Hi

God knows where the slash came from, but that does seem to have sorted the problem - sort of.

The roll-overs now work, but I still have an &quot;Error on Page&quot; in IE6. When ever I click on the icon to view the error it flashes on screen for a second, then disapears.

I vaugley remember seeing something to do with OnLoad in the <Body> tag causung problems with external .js files, but I may be wrong (I have a preload images script using OnLoad in the body tag)


Any help appreciated
 
When putting your script out of yout page. Did you think to remove the &quot;<script></script>&quot; tags in the JS file ? Water is not bad as long as it stays out human body ;-)
 
Hm, as long as you load your external .js file in, say, the header, then calling something in the body doesn't seem like it ought to be a problem. Once I moved to an external .js file, then a LOT of problems with function order simply disappeared.

Please post your exact link from the HTML page and the first line or two of your .js file. Also, if you can get a line number for the error, that might be helpful.

Consider commenting out the onload event in your HTML and seeing what happens. A common bit of troubleshooting is to just comment everything out and then uncomment it one element at a time until you see a failure. Isolate, then masticate, then celebrate.

Cheers,

Edward &quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Yup, script tags removed from the external file. Changed the call to the external script as posted above and I'm getting the right results, but with an error message in IE6

I've just tried removing the onload=&quot;MM_preloadImages.....&quot; from the <body> tag and the page loads fine with no error messages, can anyone tell me what I need to do to make it work without error messages, but with the onload included?
 
Heres the script and start of body tags from the HTML page:-

<meta http-equiv=&quot;imagetoolbar&quot; content=&quot;no&quot; />
<script src=&quot;script.js&quot; type=&quot;text/javascript&quot;></script>

<link href=&quot;CSS/text.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; />
</head>
<body bgcolor=&quot;#666666&quot; onload=&quot;MM_preloadImages('images/home_over_1.gif'

And this is the start of the .js page:-

<!--
function MM_reloadPage(init)
{ if (init==true) with (navigator) {if ((appName==&quot;Netscape&quot;)&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

I can't get the line number off the error message as the damn thing won't stay on the screen long enough for me to read it!
 
Remove the errors from the function called in the onLoad routine, of course. 8)

If it's caling a single function, then go through your .js file and toss in alert(&quot;here so far!&quot;); lines, sliding them down until you hit your error before you hit the alert.

If it helps, then monitor a variable or two in your alert box:
Code:
alert(&quot;CurrentFile name: &quot; + CurrentFileName);

Cheers,

Edward &quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
When you see &quot;Programmer&quot; next to my name, its only there because it was the closest from the list!

I'm affraid I don't realy understand what you've just posted (sorry for my ignorance).

If possible could you explain in lamens terms please?

Thanks for your help!
 
No worries, we go step-by-step.

In your .js file is a function called MM_preloadImages. If it's not too large, copy it here.

Cheers,

Edward &quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
I'm realy sorry for messing you about, I've just checked the .js file and I've left the preloadimages out - put it in and everything works fine.

Apologies for wasting your time, but thanks for helping out.
 
Hi Charlie,

Then you definitely know the problem is in the preload images function.

You might still want to troubleshoot that code, however. Preloading images is very handy with mouseover events. Without preloading images, when you mouseover, the client has to make another request to the server for the new image. This means that the first time a client mouses over an image, it takes a second or three for the new image to appear.

Just a precaution...

Glad it all works hunky dory for you. Have you tried after doing a complete page-refresh (not just hitting F5, but holding the CTRL key down and clicking on the refresh button? This is supposed to clear out your cache and when your cache is cleared out, then you'll understand better what preloading images is good for. 8)

cheers,

Edward &quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top