Accessing external Javascripts for information

J

John B.

In an effort to turn a little more a module with my pages, I would

like to turn my internal javascripts into an external javascript files

to supply the information onto a web page.



I still getting the hang of javascript, and I've searched the web, but

I'm either putting the wrong key words into the search engines, or

it can't be done. I've also done a quick search here, but some of

the answers about external javascript examples seem to deal with

issues of displaying CSS.



Here's an example page that contains a javascript that I would like

to turn into an external file:

=========================================

<HTML><HEAD><TITLE>Title of your page</TITLE>



<script language="JavaScript"><!--

function dateString(oneDate) {

var theYear = oneDate.getFullYear()

return theYear

}//--></script>



</HEAD><BODY>



<p>This is the year:

<script language="JavaScript" type="text/JavaScript"
document.write(dateString(new Date()))</script>

</p>



</BODY></HTML>

=========================================



If I can see how the simple example above is turned into an

external file and accessed from within the page, then I should

be able to figure out how to do my other scripts.



Thanks for any insight.
 
E

Evertjan.

John B. wrote on 04 jul 2003 in comp.lang.javascript:
If I can see how the simple example above is turned into an
external file and accessed from within the page, then I should
be able to figure out how to do my other scripts.

Make a file called myjs.js with only(!!):

function dateString(oneDate) {
return oneDate.getFullYear();
};

and call this in the <head> of yourhtml.html as:

<script type="text/JavaScript"src="\myjs.js">
</script>

Then later on in that same file's <body> you do:

<script type="text/JavaScript">
d = new Date();
document.write("This is the year: "+dateString(d));
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top