# Any way to call variables from outside a JavaScript file?

**URL:** https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495
**Category:** Factual Questions
**Created:** [September 18, 2003, 11:00pm UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495 "2003-09-18T23:00:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [September 18, 2003, 11:00pm UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495/1 "2003-09-18T23:00:17Z")

</div>

I’m doing a site for a client who needs to update a very small amount of text (and a link) on a regular basis.

The text and link need to be on every page, so to facilitate this I’ve got a JavaScript file that’s called by each HTML file. Thing is, I want to make it really easy for him to update, so rather than have him tinkering around inside the .js file, I’d rather use a simple .txt (or .js) file that he can just enter the link and text into. I don’t know of any way in JS to call in another file.

Anyone got any ideas? I can’t use Perl or ASP or CFM or anything like that - it’s HTML and JS only.

---

<div class="post-metadata">

### Author: ![owlofcreamcheese](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@owlofcreamcheese](https://boards.straightdope.com/u/owlofcreamcheese)
#### Post date: [September 18, 2003, 11:34pm UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495/2 "2003-09-18T23:34:29Z")

</div>

server side includes possible? that would do it, sorta like a .h file in C but for html…

---

<div class="post-metadata">

### Author: ![Big-Ole-Steve](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Big-Ole-Steve](https://boards.straightdope.com/u/Big-Ole-Steve)
#### Post date: [September 18, 2003, 11:55pm UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495/3 "2003-09-18T23:55:28Z")

</div>

I just tried this and it worked with IE. YMMV I created two separate .js files, included them both into the HTML like thus:  
file1.js:

```auto

var test1 = "This is a test";

```

file2.js

```auto

document.write("Value: " + test1);

```

And the HTML includes them both:

HTMLFile:

```auto

<html><body>
	<script type="text/javascript" src="file1.js"></script>
	<script type="text/javascript" src="file2.js"></script>
</html></body>

```

This, in IE reported:  
Value: This is a test

Therefore you could have a very simple JS file that your guy CAN edit:

```auto

var strURL = "http://www.fatchicksinpartyhats.com";
var strText = "I love fat chicks in party hats!";

```

That should be an easy enough file for him to play with, yes?

Steve

---

<div class="post-metadata">

### Author: ![Duckster](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/duckster/32/1244_2.png) [@Duckster](https://boards.straightdope.com/u/Duckster)
#### Post date: [September 19, 2003, 1:58am UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495/4 "2003-09-19T01:58:18Z")

</div>

Yes, it works. But this creates a user dependency. Anyone visiting the web site with JavaScript turned off will not see the content you are attempting to display.

Go the SSI route. It’s the better option. It’s professional. It’s the correct way to go.

---

<div class="post-metadata">

### Author: ![Sam\_Stone](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Sam\_Stone](https://boards.straightdope.com/u/Sam_Stone)
#### Post date: [September 19, 2003, 2:39am UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495/5 "2003-09-19T02:39:14Z")

</div>

What technology are you using? Server side is definitely the way you want to go. If you’re using something that supports ASP or JSP, you could make a simple file that is parsed and loaded into application variables. Then just include them on each page.

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [September 19, 2003, 8:08am UTC](https://boards.straightdope.com/t/any-way-to-call-variables-from-outside-a-javascript-file/202495/6 "2003-09-19T08:08:25Z")

</div>

Can’t do server-side. It’s JavaScript or nothing.

Don’t care about the JS being off - that’s not my problem. Anyway, it’s for a travel agency, so the site isn’t going to

**Big Ole Steve** has what I’m going to do - it came to me too as I was brushing my teeth last night.

Thanks for everyone’s advice!
