473,385 Members | 1,396 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,385 software developers and data experts.

How to create JS includes

Hello,

This should be a simple question to anyone who knows JavaScript, but I'm new
to it.

I have a JavaScript that I need to use in many pages. How do I create JS
includes?

I tried the standard method - created a text file, then includud it like
this:

<!-------------#Include File="includes/js.txt"------------------->

but this did't work for me.

I would appreciate your advice.

Thank you,

--
Peter Afonin
Jul 23 '05 #1
7 1344
Peter this is how:

<html>
<head>
<title>Test!</title>
<!-- now include script tag with src attribute pointing to -->
<!-- to your script -->
<script language="javascript" type="text/javascript" src="test.js">
<!-- //

// -->
</script>
</head>
<body>
Hello World!
</body>
</html>

Peter Afonin wrote:
Hello,

This should be a simple question to anyone who knows JavaScript, but I'm new
to it.

I have a JavaScript that I need to use in many pages. How do I create JS
includes?

I tried the standard method - created a text file, then includud it like
this:

<!-------------#Include File="includes/js.txt"------------------->

but this did't work for me.

I would appreciate your advice.

Thank you,

Jul 23 '05 #2
Thank you!

I assume that test.js is just a text file that I assign a "js" extension,
correct?

Peter

"Cycloneous Echevarria" <or*****@engr.uconn.edu> wrote in message
news:40**************@engr.uconn.edu...
Peter this is how:

<html>
<head>
<title>Test!</title>
<!-- now include script tag with src attribute pointing to -->
<!-- to your script -->
<script language="javascript" type="text/javascript" src="test.js">
<!-- //

// -->
</script>
</head>
<body>
Hello World!
</body>
</html>

Peter Afonin wrote:
Hello,

This should be a simple question to anyone who knows JavaScript, but I'm new to it.

I have a JavaScript that I need to use in many pages. How do I create JS
includes?

I tried the standard method - created a text file, then includud it like
this:

<!-------------#Include File="includes/js.txt"------------------->

but this did't work for me.

I would appreciate your advice.

Thank you,

Jul 23 '05 #3

"Peter Afonin" <pa**@specialtypulltabs.com> wrote in message
news:10*************@corp.supernews.com...
Thank you!

I assume that test.js is just a text file that I assign a "js" extension,
correct?


That is correct.
Jul 23 '05 #4
Thank you!

Peter

"Murray" <pa***@SPAMoffSPAMMER.optusSP4Mnet.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...

"Peter Afonin" <pa**@specialtypulltabs.com> wrote in message
news:10*************@corp.supernews.com...
Thank you!

I assume that test.js is just a text file that I assign a "js" extension, correct?


That is correct.

Jul 23 '05 #5
Ivo
> Peter Afonin wrote:
I have a JavaScript that I need to use in many pages. How do I create JS
includes?

"Cycloneous Echevarria" topposted Peter this is how:

<html>
<head>
<title>Test!</title>
<!-- now include script tag with src attribute pointing to -->
<!-- to your script -->
<script language="javascript" type="text/javascript" src="test.js">
<!-- //

// -->
</script>
</head>
<body>
Hello World!
</body>
</html>


A nice bare-bones example. Two remarks on the side: The script element has
no language attribute. It may have had one in the past, but that is history.
To reduce unnecessary webtraffic and in order to "validate", you should
remove the portion which reads <... language="javascript" ...> from the
script tag. Also, the custom of hiding script from older browsers by
encapsulating the script's content in <!-- --> SGML comments is obsolete.
These "older browsers" that do not know about the script tag, are history
too.

You can also make the src point to a script on another website. Socalled
hit-counters often do this. Simply by entering the whole address, including
http protocol. Just be aware that cross-domain security restrictions apply.

As a last remark, a script element that has a src defined, will ignore any
content inside the tag itself. Only if the source file is not found or there
some other error loading the external script, will the engine consider and
execute any script hardcoded inside the tag.

HTH
Ivo
Jul 23 '05 #6
JRS: In article <10*************@corp.supernews.com>, seen in
news:comp.lang.javascript, Peter Afonin <pa**@specialtypulltabs.com>
posted at Fri, 7 May 2004 09:17:37 :
I have a JavaScript that I need to use in many pages. How do I create JS
includes?

I tried the standard method - created a text file, then includud it like
this:

<!-------------#Include File="includes/js.txt"------------------->

but this did't work for me.


Bearing in mind where much system software is written, you should not
expect just one standard for anything.

See <URL:http://www.merlyn.demon.co.uk/js-nclds.htm>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7
JRS: In article <40***********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Fri, 7 May 2004
22:16:57 :
Also, the custom of hiding script from older browsers by
encapsulating the script's content in <!-- --> SGML comments is obsolete.
These "older browsers" that do not know about the script tag, are history
too.


You are here making the assumption that the script will be read only by
browsers; that is no more than an assumption.

The master copies of my own web pages are most frequently read by a
tool, CHEKLINX, which is affected by seeing these comment delimiters;
without them, the normally-satisfactory javascript if (b<a) needs
to be re-written as if (b< a) or if (b < a ) .

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8

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

Similar topics

2
by: Joe Mowry | last post by:
First off, I'm posting this question for a friend that doesn't have access to the news groups. Problem: Using PHP as the base and has several PHP < includes > for various functions, all this...
4
by: Patrick | last post by:
I have an ASP site with about 50 ASP files, all of which are currently including a common "includes.asp" file near the top of the file, responsible for generating the <HEAD/> section of the HTML ...
22
by: Peter Ammon | last post by:
A friend was asked "How many ways are there to create an object in C++?" in an interview. Apparently, the "right" answer was eleven. Does anyone know how the interviewer arrived at that number? ...
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
4
by: Scott Capistrant | last post by:
I am relatively new to the VB.net platform. How would I create a packaged exe that can run outside of my computer (i.e. load the needed dll's and such). Thanks.
10
by: ANTISPAM_garycnew_ANTISPAM | last post by:
I am trying to create/update a Php Session with Javascript to confirm if users have Javascript enabled. My first thought was to create a Javascript that writes a script tag referencing a php...
1
by: martin.zarate | last post by:
Hey, I'm just trying out the XSD.exe tool and have run into a problem - it doesn't generate classes for all the members. For example, here's my call: D:\Program Files\Microsoft Visual Studio...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
12
by: Vallabh | last post by:
I want to create a separate log that includes an I (logIN) , userid, and date/timestamp from a detailed log. This type of data compresses very well so I can store years of it. I need script to...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.