Include Javascript file

Q

qscomputing

Hi,

I am developing a series of web pages that use JS, and they are all
fairly similar except for some very small changes. What I am hoping to
do is create one page that accepts a parameter from location.search and
then uses that to include a JS file with the appropriate parts that are
different from the main page. I am aware that I could do this the other
way round (ie. several different pages that include a set of core
functions etc.), but that will not work for this project.
Is this possible in any way?

TIA for any help,
- QS Computing.
 
S

Stephen Chalmers

Hi,

I am developing a series of web pages that use JS, and they are all
fairly similar except for some very small changes. What I am hoping to
do is create one page that accepts a parameter from location.search and
then uses that to include a JS file with the appropriate parts that are
different from the main page. I am aware that I could do this the other
way round (ie. several different pages that include a set of core
functions etc.), but that will not work for this project.
Is this possible in any way?

TIA for any help,
- QS Computing.

Assumimg all the files would be included in the same place in the document,
just create an array of known filenames and search for its presence in
window.location.search:

var jsFiles=["js0.js", "js1.js", "js2.js"], l=jsFiles.length;

for(var i=0; i<l && window.location.search.indexOf(jsFiles)==-1; i++)
;
if(i!=l)
document.write("<script src='"+jsFiles+"'><\/script>");
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 24
Jan 2005 14:36:19, seen in Stephen Chalmers
for(var i=0; i<l && window.location.search.indexOf(jsFiles)==-1; i++) ;


Please don't use lower-case L in code for Usenet - you have no idea what
fonts your readers may have selected, except that fixed-pitch fonts are
common. In at least one of the best-known of those, l & 1 can be almost
indistinguishable.
 
Q

QS Computing

Unfortunately the external files are not pre-known.

But the good news is that I have worked out a workaround which does it
differently. Curiously enough, the way I said wouldn't work in the
first post of this thread!

So, I'm no longer in need of any help, but thanks anyway.

- QS Computing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top