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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS external file not being loaded

Status
Not open for further replies.

PcolaSteve

Programmer
Jul 1, 2011
30
US
I am testing an external JavaScript file but am unable to get it to load. It has got to be something simple that I am missing. Here is the JS code on the external file:

document.write("Test external link.");

That is all that is written on that file saved as: test.js

Here is the script on the main page. I have tested the script in both the 'head' and the 'body' of the code.

<script type="text/javascript" src="test.js"></script>

The src of course has the correct file path, so I can't understand why it isn't loading. (I do belive there may be an issue with the file path but I have verified it more than once.

Any suggestions?
 
It's probably loading, but as the code is not in a function, or being called, it won't do anything.

Try test.js looking like this
Code:
function start(){
document.write("Test external link.");}
and test.htm looking like this:
Code:
<html><head><script type="text/javascript" src="test.js"></script></head>
<body onload="start()">
</body>
</html>

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Are both files located in the same folder?

The .js file and the page file?

Also if the main page has a lot of stuff it may be itself covering or obscuring the text from the JS file.

Additonally if any other JS is running that may overwrite the page it could also be getting deleted.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks to both of you. You kicked the cobwebs out of my head. Both of your suggestions made me look at something and it's working now. It was a combination of transposed letters in a file name and another simple typo.

The shortest distance between two points is NOT a straight line; it's a worm hole!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top