Connecting Tech Pros Worldwide Forums | Help | Site Map

How to create JS includes

Peter Afonin
Guest
 
Posts: n/a
#1: Jul 23 '05
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



Cycloneous Echevarria
Guest
 
Posts: n/a
#2: Jul 23 '05

re: How to create JS includes


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:
[color=blue]
> 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,
>[/color]
Peter Afonin
Guest
 
Posts: n/a
#3: Jul 23 '05

re: How to create JS includes


Thank you!

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

Peter

"Cycloneous Echevarria" <orlando@engr.uconn.edu> wrote in message
news:409BBBC3.8020807@engr.uconn.edu...[color=blue]
> 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:
>[color=green]
> > Hello,
> >
> > This should be a simple question to anyone who knows JavaScript, but I'm[/color][/color]
new[color=blue][color=green]
> > 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,
> >[/color][/color]


Murray
Guest
 
Posts: n/a
#4: Jul 23 '05

re: How to create JS includes



"Peter Afonin" <pafo@specialtypulltabs.com> wrote in message
news:109nicvc1g1r393@corp.supernews.com...[color=blue]
> Thank you!
>
> I assume that test.js is just a text file that I assign a "js" extension,
> correct?[/color]

That is correct.


Peter Afonin
Guest
 
Posts: n/a
#5: Jul 23 '05

re: How to create JS includes


Thank you!

Peter

"Murray" <parps@SPAMoffSPAMMER.optusSP4Mnet.com.au> wrote in message
news:409bcc3b$0$25007$afc38c87@news.optusnet.com.a u...[color=blue]
>
> "Peter Afonin" <pafo@specialtypulltabs.com> wrote in message
> news:109nicvc1g1r393@corp.supernews.com...[color=green]
> > Thank you!
> >
> > I assume that test.js is just a text file that I assign a "js"[/color][/color]
extension,[color=blue][color=green]
> > correct?[/color]
>
> That is correct.
>
>[/color]


Ivo
Guest
 
Posts: n/a
#6: Jul 23 '05

re: How to create JS includes


> Peter Afonin wrote:[color=blue][color=green]
> > I have a JavaScript that I need to use in many pages. How do I create JS
> > includes?[/color][/color]

"Cycloneous Echevarria" topposted[color=blue]
> 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>[/color]

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


Dr John Stockton
Guest
 
Posts: n/a
#7: Jul 23 '05

re: How to create JS includes


JRS: In article <109ndofba7luk54@corp.supernews.com>, seen in
news:comp.lang.javascript, Peter Afonin <pafo@specialtypulltabs.com>
posted at Fri, 7 May 2004 09:17:37 :
[color=blue]
>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.[/color]

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.
Dr John Stockton
Guest
 
Posts: n/a
#8: Jul 23 '05

re: How to create JS includes


JRS: In article <409beeb0$0$54139$1b2cd167@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Fri, 7 May 2004
22:16:57 :
[color=blue]
> 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.[/color]

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.
Closed Thread