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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.