billven billven - 11 months ago 52
HTML Question

Call javascript from HTML

I have a HTML file with the content:

<script src="">
function test()
//Function stuff

However, I'd like to write all my javascript (Function test) in a separate document (.js). How do I refer to, or call, this separate file so I get the same result as if the code was directly in the HTML?

I need the to ease the graphics handling in function test.

Answer Source

In the html section, refer to the file that contains your javascript, I'm assuming the html file is in the same folder as that containing your script.

<script src="script.js"></script>

If the script is in a different folder...

<script src="/path/to/script.js"></script>