-1

I have a HTML file with the content:

<script src="http://spelprogrammering.nu/simple.js">
function test()
{
//Function stuff
}
</script>

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 http://spelprogrammering.nu/simple.js to ease the graphics handling in function test.

4lackof
  • 1,250
  • 14
  • 33
billven
  • 11
  • 2

4 Answers4

1

You already have what you need in your source.

<script src="http://spelprogrammering.nu/simple.js"></script>
Brad
  • 159,648
  • 54
  • 349
  • 530
0
<script src="http://spelprogrammering.nu/simple.js"></script>
<script src="main.js"></script>

Where main.js contains your function.

SchattenJager
  • 333
  • 3
  • 15
  • Not sure why this was downvoted. It answers the question exactly as asked, where the OP wants to include a library and his own code in two separate files. – SchattenJager Sep 15 '16 at 20:21
0

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>
OSMadeIT
  • 57
  • 3
  • 11
-1

I think that you say that? in this case you need to make difrent script calling your .js

<code>
<script src="http://spelprogrammering.nu/simple.js"></script>
<script src="http://spelprogrammering.nu/other.js"></script>
<script src="http://spelprogrammering.nu/other2.js"></script>