This is a discussion on "External Javascript" within the JavaScript Forum section. This forum, and the thread "External Javascript are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
External Javascript
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
External Javascript
Hi,
I've read on these forums that its good to put Javascript in an external .js file so that the page size is smaller. I've tried putting the following bit of Javascript (which prints put the date) into an external file but how can I then reference it to put the date into the right place on my page? Is this just the kind of Javascript that I cant make external to a page? Any help would be appreciated. Mike <script type="text/javascript" language="JavaScript1.2"><!-- var mydate=new Date() var year=mydate.getYear() if (year < 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym<10) daym="0"+daym var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thu rsday","Friday","Saturday") var montharray=new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December") document.write("<font color='ffffff' face='verdana' size='1'>"+montharray[month]+" "+daym+", "+year+"<\/b>") // --> </script> |
|
|
|
||||
|
that sort of javascript, with the document.write(), you can't put in an external javascript file. However, you can do this:
You can put the string that you want to write into the page in an external javascript file in a variable like this:
|
|
|||
|
Ben,
Many thanks for your help. I've put that code in and its much neater. At the moment I'm copying and pasting into Dreamweaver 3. Do you know of any good software for debugging javascript (preferably free)? Mike |
|
||||
|
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />Originally posted by benbacardi
I don't myself, all I ever use to make my websites is good old Notepad!!<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">and I thought I was the ONLY one..... :wink:
__________________
Rob - SEO Specialist Owner & Founder of Webforumz.com I am currently unavailable for private work
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
![]() |
| Tags |
| external, javascript |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| External HD | Ryan Fait | Webforumz Cafe | 16 | Jan 11th, 2008 13:28 |
| external javascript problem | Damian | PHP Forum | 0 | Dec 5th, 2007 09:44 |
| external js | alexgeek | JavaScript Forum | 6 | Sep 23rd, 2007 20:57 |
| Problem with IE, think its external javascript includes | rewind1000 | JavaScript Forum | 5 | Aug 19th, 2005 12:00 |