Jump to content

Strange simple problem


Jesper

Recommended Posts

Hey everyone, for some reason my very basic javascript code is not working.

 

The code I'm using is:

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

<body>
</body>

</html>

 

in the file test.html.

 

In the file test.js I have:

document.write("testing");

 

I suppose this should work, but strangely enough, it doesn't. When I just use the document.write inside the script tag and remove the src part, it does work. Does anyone know what could be the cause (I'm possibily missing something very obvious).

 

Link to comment
https://forums.phpfreaks.com/topic/129850-strange-simple-problem/
Share on other sites

Well, you are executing that code within the head of your document.  If you view the rendered source code you will probably see it there.  If you made it into a function and then called the function from within the body it will probably be visible.

DropFaith's code left out the language="javascript" part.

 

If restarting your computer fixed it, it was probably a cache issue. Also, when making changes to your test.js, you'll want to refresh it. Open it in a different tab and refresh it before refreshing your main page. That will ensure that you're using the new code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.