473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.

Jul 23 '05 #1
3 1283

<qs*********@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
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[i])==-1; i++)
;
if(i!=l)
document.write("<script src='"+jsFiles[i]+"'><\/script>");

--
S.C.
Jul 23 '05 #2
JRS: In article <41**********@mk-nntp-2.news.uk.tiscali.com>, dated Mon, 24
Jan 2005 14:36:19, seen in news:comp.lang.javascript, Stephen Chalmers
<ig******@lycos.co.uk> posted :
for(var i=0; i<l && window.location.search.indexOf(jsFiles[i])==-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.

--
© 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.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #3
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.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Peter Bassett | last post by:
I have a .shtml file, that displays photos, in which I wish to pass some functionality off to an Include file for reusability purposes. Unfortunately, it's not working. Here is a portion of the...
22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
6
by: Spartanicus | last post by:
For a non essential enhancement of one of my pages I'd like to include a remote html file via javascript (server side is not available to me). The "include" method that I'm familiar with: ...
6
by: Jamie | last post by:
Hi there, I have a bit of java script which I would like to include in all of my html pages. Is there an easy way to include it with a reference or something. I don't want to have to copy...
5
by: Tony Strazzeri | last post by:
Hi all, I a fairly new to html and Javascripting. I have been trying to write some code to hide my email address from spam harvesters. I copied the code from various web examples and modified...
3
by: Brit | last post by:
Hello, I have been trying to include a js file from within another js file. I can get this to work for firefox, but not i.e. What I have is a.html ... <script language='JavaScript'...
2
by: WL | last post by:
Hi, I seem to have a bizar problem: I have a .HTML file with: <script language="javascript" src="include.aspx"></script> In the include.aspx (on load) I do: Response.ClearContents();...
14
by: Julesh | last post by:
Hello, I am new to ASP and am trying to make some changes to some ASP 3.0 code I have inherited. I have a number of ASP pages with VBS as the base language, on each of these pages I have...
1
by: Carafound | last post by:
Help!!! I am trying to write an ASP include statement <!--#include file="file.asp"--to an HTML stream in a new window using Javascript document.write command. The page gets built however the...
4
by: rocketeer | last post by:
I've a set of Javascript classes that maintain state. For example, gm.js might be: var GroupManager { groups: {} }; Over time I add new groups to the list: GroupManager.groups = myGroup; ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.