homepage Welcome to WebmasterWorld Guest from 54.167.177.180
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JAVASCRIPT - Linking javascipt files in other javascript files
Hot_Denim2

10+ Year Member



 
Msg#: 342 posted 2:32 am on Apr 4, 2003 (gmt 0)

I use IE5. And Javascript. In a javscript file e.g. abc.js is it possible to include another javascript file? so the other files functions can also be used?... like a libray routine.

... a but like C languages #INCLUDE etc...

 

korkus2000

WebmasterWorld Senior Member korkus2000 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 342 posted 3:11 am on Apr 4, 2003 (gmt 0)

Not that I know of.

>>I use IE5
Are you creating a desktop application?

Hot_Denim2

10+ Year Member



 
Msg#: 342 posted 3:33 am on Apr 4, 2003 (gmt 0)

No

korkus2000

WebmasterWorld Senior Member korkus2000 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 342 posted 3:38 am on Apr 4, 2003 (gmt 0)

Is this going to go on the web?

Hot_Denim2

10+ Year Member



 
Msg#: 342 posted 3:46 am on Apr 4, 2003 (gmt 0)

yes

ShawnR

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 342 posted 3:58 am on Apr 4, 2003 (gmt 0)

You can get a similar effect to a #include by including the javascript files in your html file. For example, with the following in your html file:

<script language="JavaScript" src="scripts/file1.js"></script>
<script language="JavaScript" src="scripts/file2.js"></script>

If you define a variable, function or whatever in file1.js, you can call your function, or reference your variable from code in file2.js

Shawn

ricfink

10+ Year Member



 
Msg#: 342 posted 3:58 am on Apr 4, 2003 (gmt 0)

yeah, sure.

Two things come to mind:

First, the obvious - load two (or more) .js files with the document and code from one file can reference code in the other file.
But both files must be linked to the document.

More in line with what I think you're looking to do is to link to a scripted page which returns javascript and can contain an include just like any other scripted page.
Details:

<script type="text/javascript" src="mainscript.asp"></script>

In the mainscript.asp page you set the response.contenttype to "text/javascript" so that it returns data with the proper type.
From there on in, you can include code to your heart's content just like any other asp page. It's just got to be valid, working javascript.

This can be done with any sophisticated server-side scripting engine. PHP for sure.

gethan

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 342 posted 4:23 am on Apr 4, 2003 (gmt 0)

A nasty cludge is to make the javascript write out the includes it needs as html... eg.

includefile = 'somefile determined dynamically';
document.write('<script type='text/javascript src="'+includefile+'"></script>');

nasty - I've used this on IE 5.5 only - not sure if it will work on other browsers.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved