[thelist] Pass variable to js include file?

Joshua Olson joshua at waetech.com
Wed Sep 25 22:17:01 CDT 2002


----- Original Message -----
From: "Ryan Carmody" <carmodyryan at hotmail.com>
Sent: Wednesday, September 25, 2002 11:04 PM


> Is it possible to pass a var to a js include file?  I have a path in a js
> include file that I need to unhardcode and can't figure out how to pass
that
> path as a var.  Any help is appreciated.

Ryan,

If you define the variable in a script block in the header prior to the
include, the defined variable will be available within the included file.
EG:

<script language="JavaScript" type="text/javascript">
  var myvar = 1;
</script>

<script language="JavaScript" src="includeme.js"
type="text/javascript"></script>

Another option is to have your favorite script engine, such as CF, PHP, etc,
actually parse js files.  Then you can simply do this:

<script language="JavaScript" src="includeme.js?myvar=1"
type="text/javascript"></script>

The second platform is only an option if you have the means to change the
way the web server operates.  In IIS it means adding the js extension to the
list of extension parsed by an installed parser.  In apache... I dunno.

HTH,
-joshua




More information about the thelist mailing list