Click to See Complete Forum and Search --> : How to import?


just_a_w
08-14-2003, 01:30 PM
I am trying to figure out how/if I can import a .js file. I have a Javascript (.js) file and I want to have another .js file with my constants (variables). I'd like to import the .js file of constants into my 'working' file.

In Java, I would just create a class and import it. But that doesn't seem to work here.

Any suggestions?

Thanks,

Mr J
08-14-2003, 01:38 PM
Just save your variables and values in a .js file (your_varables) and put

<script language="javascript" src="your_varables.js"></script>

in the head section of your document

just_a_w
08-14-2003, 01:47 PM
The caveat to my situation is that the script itself isn't going in a webpage. I have a .js file (file1.js), and I want to import another .js file (file2.js) into file1.js.

Charles
08-14-2003, 02:21 PM
1) The "language" attribute was depricated back in 1997. Use the "type" attribute instead.

2) JavaScript cannot communicate with other files, but HTML can and JavaScript can write HTML.

document.write('<script type="text/css" src="constants.js"></script>');

Mr J
08-14-2003, 04:17 PM
1) The "language" attribute was depricated back in 1997. Use the "type" attribute instead.

That maybe true but it is still used in the very source code of this page

:cool: