Include Javascript file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qscomputing@gmail.com

    #1

    Include Javascript file

    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.

  • Stephen Chalmers

    #2
    Re: Include Javascript file


    <qscomputing@gm ail.com> wrote in message
    news:1106482718 .792554.33490@c 13g2000cwb.goog legroups.com...[color=blue]
    > 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.
    >[/color]

    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.lengt h;

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

    --
    S.C.


    Comment

    • Dr John Stockton

      #3
      Re: Include Javascript file

      JRS: In article <41f507d4$1_3@m k-nntp-2.news.uk.tisca li.com>, dated Mon, 24
      Jan 2005 14:36:19, seen in news:comp.lang. javascript, Stephen Chalmers
      <ignoring@lycos .co.uk> posted :
      [color=blue]
      >for(var i=0; i<l && window.location .search.indexOf (jsFiles[i])==-1; i++) ;[/color]

      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
      indistinguishab le.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
      Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
      Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
      No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

      Comment

      • QS Computing

        #4
        Re: Include Javascript file

        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.

        Comment

        Working...