# How can I reference this Javascript externally?

**URL:** https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178
**Category:** Factual Questions
**Created:** [August 10, 2007, 9:28pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178 "2007-08-10T21:28:49Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Red\_Barchetta](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Red\_Barchetta](https://boards.straightdope.com/u/Red_Barchetta)
#### Post date: [August 10, 2007, 9:28pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178/1 "2007-08-10T21:28:49Z")

</div>

There’s a nifty javascript applet on this page that I’d like to add to my site (click “View Source” to see the scropt):  
[http://www.nsftools.com/tips/ImageResize.htm](http://www.nsftools.com/tips/ImageResize.htm)

Everything works great, except I need to paste the entire Javascript in the “Head” of every page. Is there a way for me to place the script in its only .js file and reference it that way?

Thanks.

---

<div class="post-metadata">

### Author: ![MrSquishy](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@MrSquishy](https://boards.straightdope.com/u/MrSquishy)
#### Post date: [August 10, 2007, 9:45pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178/2 "2007-08-10T21:45:44Z")

</div>

Sure.

Stick the code in a file called “rolloverscript.js” (or whatever you want). Put that file in the same directory with all your HTML files. Then stick this in the HEAD of your HTML files:

```auto

<script language='JavaScript' src='rolloverscript.js'></script>

```

Is that what you meant? Or did I misunderstand the question?

---

<div class="post-metadata">

### Author: ![Red\_Barchetta](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Red\_Barchetta](https://boards.straightdope.com/u/Red_Barchetta)
#### Post date: [August 10, 2007, 9:54pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178/3 "2007-08-10T21:54:09Z")

</div>

No, you understood it just fine. The only problem is that when I try that, the actual commands that draw upon that script (in the table containing the circles that enlarge) don’t seem to know where to draw it from, if that makes sense.

In short, the script doesn’t work when I try that.

---

<div class="post-metadata">

### Author: ![I\_m\_Ron\_Burgundy](https://avatars.discourse-cdn.com/v4/letter/i/9fc29f/32.png) [@I\_m\_Ron\_Burgundy](https://boards.straightdope.com/u/I_m_Ron_Burgundy)
#### Post date: [August 10, 2007, 10:08pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178/4 "2007-08-10T22:08:29Z")

</div>

It depends on where the file is located on the server, in relation to the pages it’s referenced in. If it is located in the root directory of your website, try

```auto

<script language='JavaScript' src='/rolloverscript.js'></script>

```

If it is located in a directory called ‘jscript’

```auto

<script language='JavaScript' src='/jscript/rolloverscript.js'></script>

```

---

<div class="post-metadata">

### Author: ![Red\_Barchetta](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Red\_Barchetta](https://boards.straightdope.com/u/Red_Barchetta)
#### Post date: [August 10, 2007, 10:10pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178/5 "2007-08-10T22:10:59Z")

</div>

Thanks, but I made sure the url is correct, yet it still doesn’t work for some reason. Could it be because the table where the effect is used doesn’t appear to refer to the javascript by name?

Edit: Also, do I need the “\<script language=JavaScript\>” and "\</Script\> in the .js file itself?

---

<div class="post-metadata">

### Author: ![Red\_Barchetta](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Red\_Barchetta](https://boards.straightdope.com/u/Red_Barchetta)
#### Post date: [August 10, 2007, 10:13pm UTC](https://boards.straightdope.com/t/how-can-i-reference-this-javascript-externally/415178/6 "2007-08-10T22:13:15Z")

</div>

Nevermind, I’m an idiot. I got it working (the file had two .js extensions by mistake. Thanks everyone!
