473,806 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1356
Peter this is how:

<html>
<head>
<title>Test!</title>
<!-- now include script tag with src attribute pointing to -->
<!-- to your script -->
<script language="javas cript" 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.u conn.edu> wrote in message
news:40******** ******@engr.uco nn.edu...
Peter this is how:

<html>
<head>
<title>Test!</title>
<!-- now include script tag with src attribute pointing to -->
<!-- to your script -->
<script language="javas cript" 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**@specialty pulltabs.com> wrote in message
news:10******** *****@corp.supe rnews.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***@SPAMoffS PAMMER.optusSP4 Mnet.com.au> wrote in message
news:40******** *************** @news.optusnet. com.au...

"Peter Afonin" <pa**@specialty pulltabs.com> wrote in message
news:10******** *****@corp.supe rnews.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="javas cript" 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="javas cript" ...> 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.supernew s.com>, seen in
news:comp.lang. javascript, Peter Afonin <pa**@specialty pulltabs.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.demo n.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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7
JRS: In article <40************ ***********@new s.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
encapsulatin g 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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
1611
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 by its self works just fine. Failure occurs on adding the XML include. Here's the wierd: If all the PHP includes are removed/commented out,
4
1635
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 I need to make a change for 3 of those ASP files such that some dynamic HTML is generated in the <HEAD/> section. I want those dynamic HTML to appear only for 3 specific ASP files. Is there a more elegant way other than to 1) Dim...
22
7880
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? Is this fact well known (if true)?
9
2089
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
1437
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
3931
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 page, which sets a $_SESSION variable. javascript.js: <script type="text/javascript"> <!--//
1
2617
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 8\SDK\v2.0\Bin>XSD D:\projects\Repricer \Repricer\bin\Debug\Repricer.exe /outputdir:D:\projects\Repricer\Repricer /t:Mut ator /t:Source
4
12454
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
12
9529
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 create an separate log files that can saved on each server. Since I dont know much about perl scripting. Your help will be appreciated. Thanx Val
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10371
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.