473,511 Members | 15,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i put my script in an extern file?

I have a script placed somewhere in the body of my HTML-doc.
I noticed that i'll be using the very same script in a large number
of document (all of them as the script regards the time of the
most recent edition of the given file).

I could place the script in every single document BUT:
1. I'm far too lazy to go through 100 documents doing one and the
same thing. That's for monkeys, not lazy humans.
2. Even if i wasn't so lazy, i'd have to reedit every single
document once i made a small change to the script. That's for
crazy monkeys!

So, how can i place the script in a file and how do i call the
file from my HTML-code?

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


Jul 23 '05 #1
11 1712
JW
It's easy. In the HTML-file you put :
<script language="JavaScript" src="yourscriptfile.js"></script>

And you place your scriptfile in the "yourscriptfile.js"
JW
Jul 23 '05 #2
Just put

<script language="javascript" src="nameofyourscript.js"></script>

between the <head> tags...

The page will automatically read it as if it was in the
page itself...

Greetings
Jul 23 '05 #3
Thanks, Will try that tonight.

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


Jul 23 '05 #4
Konrad Den Ende wrote on 21 jun 2004 in comp.lang.javascript:
Thanks, Will try that tonight.


This is no email, this is usenet posting.
So, for the benefit of all the other readers,
quote a significant [in the quality sense] part of the mail
you are referring to, [without resorting to topposting]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #5
"JW" <ja*******@hotpop.com> writes:
It's easy. In the HTML-file you put :
<script language="JavaScript" src="yourscriptfile.js"></script>
The "type" attribute is required on script elements in HTML 4. The
"language" attribute is deprecated and can safely be omitted.
So, the recommended (and validating) way to write it would be:

<script type="text/javascript" src="yourscriptfile.js"></script>
And you place your scriptfile in the "yourscriptfile.js"


(and remember not to have <script> tags in the javascript file)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6
> So, the recommended (and validating) way to write it would be:

<script type="text/javascript" src="yourscriptfile.js"></script>


I have placed following in the <head>
<script type="text/javascript" src="scripts.js"></script>
and made the script itself to a function returning a string as in
function getSome () { ... }
Then i call it by
<script>document.write (getSome ());</script>
but i get the message that the site is loaded but it contains errors.
I can't see the text i'm supposed to, either. What did i miss?

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


Jul 23 '05 #7
Konrad Den Ende wrote:
So, the recommended (and validating) way to write it would be:

<script type="text/javascript" src="yourscriptfile.js"></script>

I have placed following in the <head>
<script type="text/javascript" src="scripts.js"></script>
and made the script itself to a function returning a string as in
function getSome () { ... }
Then i call it by
<script>document.write (getSome ());</script>
but i get the message that the site is loaded but it contains errors.
I can't see the text i'm supposed to, either. What did i miss?

The scripting in the external .js file must be without opening and
closing HTML-tags
Also check if you can read the .js file directly from your server, maybe
you must update/change the index.cache files

If your browser says it contains errors, check out in which lines of
your page (in IE doubleclick on the yellow triangle)

I do it this way on a working site (eg. putting address info under each
page on http://www.autowiegel.nl)
In HEADER:
<script src="data1.js" language="javascript"></script>

in BODY:
<SCRIPT language="Javascript">
<!--
document.write(voettxt1)
//-->
</script>

The data1.js file contains the following (you'll notice a function
inside it too, but you can of course remove it);

<!--
function newwin2(page) {
empty =
open(page,"empty","width=630,height=470,status=0,s crollbars=1,resizable=0,location=0,menubar=1,top=1 00px,left=100px");
}
var voettxt1 = "<HR><CENTER><TABLE align=middle bgColor=#ffffff
border=0><TBODY><TR><TD><FONT face=arial,helvetica size=-1>Auto Wiegel
B.V.<BR>Korteweg 1<BR>2641 GZ Pijnacker<BR><A
href=javascript:newwin2('routemap.htm')><FONT
color=blue>Routekaart</FONT></A></FONT></TD><TD
width=25>&nbsp;</TD><TD><FONT face=arial,helvetica size=-1><TABLE
border=0><TBODY><TR><TD><FONT face=arial,helvetica
size=-1>Tel.<BR>Fax.<BR>E-mail.<BR>Internet.</FONT></TD><TD><FONT
face=arial,helvetica size=-1>+31 (0)15 369 22 52<BR>+31 (0)15 369 60
29<BR>in**@autowiegel.nl<BR>www.autowiegel.nl</FONT></TD></TR></TBODY></TABLE></FONT></TD></TR></TBODY></TABLE></CENTER>";
//-->

See the result on, for instance, http://www.autowiegel.nl/pag02.htm

Richard

Jul 23 '05 #8
> Also check if you can read the .js file directly from your
server, maybe you must update/change the index.cache files


Hehe, it helps if one point to the right directory. Stupid mistake...
I put the file in an other directory (though one with the same
name but different path).

Nevertheless, i can't keep wondering about an ambigousity i see
here. What happens if i have two different functions stored in
two different files, yet call them the same name. Which one will
the computer thing i'm refering to?

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


Jul 23 '05 #9
Richard Hijdra wrote:
Konrad Den Ende wrote: <snip> The data1.js file contains the following (you'll notice a function
inside it too, but you can of course remove it);

<!--

^^^^

You have put this in an external JS file? Why? In javascript it is -
less than NOT pre-decrement - and a syntax error as there are not
operands for the operations.

Richard.
Jul 23 '05 #10
>> <!--
^^^^

You have put this in an external JS file? Why? In javascript it
is - less than NOT pre-decrement - and a syntax error as there
are not operands for the operations.


Do you mean that it's not the right syntax for commenting out
a piece of code? What should be used?

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


Jul 23 '05 #11
Konrad Den Ende wrote:
<!--

^^^^
You have put this in an external JS file? Why? In javascript it
is - less than NOT pre-decrement - and a syntax error as there
are not operands for the operations.


Do you mean that it's not the right syntax for commenting out
a piece of code? What should be used?


Javascript syntax allows two forms of comments:-

// end of line comments using two slashes

- and:-

/* multi-line comments
surrounded by slash asterisk - asterisk slash.
*/

The character sequence used resembles an HTML opening comment tag, which
has alternative interpretations in javascript. The origin of this
nonsense is in a technique for hiding the content of script elements
from browsers that did not understand the meaning of SCRIPT elements and
so would include the contents of a script element along with the text
contents of an HTML page. But browsers that do not understand SCRIPT
elements are long since dead and gone, and it never was necessary to
attempt to use such tricks in an external JS file as a browser that does
not understand SCRIPT elements does not know that there is a JS file
associated with the SCRIPT element and so will not download it.

Richard.
Jul 23 '05 #12

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

Similar topics

0
5055
by: Richard | last post by:
I am having trouble accessing a web page programmatically from .NET. Our proxy server is determined by a PAC script and all the standard .NET (and WinHttp) proxy techniques don't work for scripts....
4
2582
by: John Ratliff | last post by:
I have a few global variables in my app. They are defined in the main application class file and declared (extern) in a header which can be included by anyone who would want to use these variables....
18
4252
by: tweak | last post by:
What's the best way to use extern when using multiplefiles that is easiest to maintain? Is it best to declare: extern int a; in a header file and include the header file in all files except...
12
2697
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
19
3822
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
5
16593
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
17
4905
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
5
2835
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
7
3513
by: blangela | last post by:
I am currently taking a course and one of the example programs showed a function prototype something like: extern void func(); I asked why the "extern" was necessary. Someone in the class...
0
7245
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,...
0
7356
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,...
0
7427
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...
1
7085
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...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1577
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 ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
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...

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.