By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Accessing external Javascripts for information

P: n/a
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.
--
Change [comcast.non] to [comcast.net]
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.