Click to See Complete Forum and Search --> : Javascript and XHTML


Ascii Art
12-05-2003, 02:32 PM
Hi.
As the very new web master of www.ukpeoplesilversurfers.co.uk I have a javascript at the foot of each page that tells visitors when the page was updated.
I am gradually converting the code to XHTML (hopefully Strict) and would like to use external scripts.
I've created a scripts folder with an 'updated.js' file saying

var modDate = new Date(document.lastModified)
var modYear = modDate.getYear()
if(modYear<1000) modYear+=1900

document.write("Page updated: " + modDate.getDate() + "." +
(modDate.getMonth()+1) + "." + (modYear+"").substring(4,2))

How do I refer to this file please?

TIA

neil9999
12-05-2003, 02:37 PM
<script language="javascript" src="updated.js">

Neil

fredmv
12-05-2003, 02:37 PM
Welcome to the forums.

So you create a new folder called scripts and a file called update.js? To refer to it should be as easy as:<script type="text/javascript" src="scripts/update.js"></script>

Ascii Art
12-05-2003, 03:02 PM
Originally posted by neil9999
<script language="javascript" src="updated.js">

Neil

Thanks Neil. Does that go at the foot of each page please?

Ascii Art
12-05-2003, 03:09 PM
Originally posted by fredmv
Welcome to the forums.

So you create a new folder called scripts and a file called update.js? To refer to it should be as easy as:<script type="text/javascript" src="scripts/update.js"></script>

Tks. Have put that in the header. I now want to see the details at the bottom of each page.

neil9999
12-05-2003, 03:17 PM
You put either code wherever you want the code to happen.

Eg.

BEFORE

<body>
bla bla bla
<script language="javascript">
var modDate = new Date(document.lastModified)
var modYear = modDate.getYear()
if(modYear<1000) modYear+=1900

document.write("Page updated: " + modDate.getDate() + "." +
(modDate.getMonth()+1) + "." + (modYear+"").substring(4,2))

</script>
</body>

AFTER

<body>
bla bla bla
<script language="javascript" src="update.js"></script>
</body>

Ascii Art
12-05-2003, 03:28 PM
[QUOTE]Originally posted by neil9999
[B]You put either code wherever you want the code to happen.

<snipped>

Tks. Off to have yet another go at it.

aka John the Recycled Teenager

Ascii Art
12-06-2003, 02:56 PM
Originally posted by Ascii Art
[QUOTE]Originally posted by neil9999
[B]You put either code wherever you want the code to happen.

<snipped>

Tks. Off to have yet another go at it.

aka John the Recycled Teenager

Tks Neil9999 and fredmv.
Link added to bottom of pages. Just what I needed.
Only another 150+ pages to update and ftp.

:)

pyro
12-06-2003, 03:07 PM
Hope I catch you before you go through too much work, because if you use neil9999's suggestion, your code will be incorrect. The language attribute has been depreciated, and was replaced by the type attribute, as fredmv demonstrated.

If you need an external script, do what fredmv showed. If you are using an internal script, do so like this (for XHTML documents):

<script type="text/javascript">
<![CDATA[
//your script here
]]>
</script>

Ascii Art
12-06-2003, 06:14 PM
Originally posted by pyro
Hope I catch you before you go through too much work, because if you use neil9999's suggestion, your code will be incorrect. The language attribute has been depreciated, and was replaced by the type attribute, as fredmv demonstrated.

If you need an external script, do what fredmv showed. If you are using an internal script, do so like this (for XHTML documents):

<script type="text/javascript">
<![CDATA[
//your script here
]]>
</script>

Thanks for the warning, and yes, you have caught me before updating the rest of the pages as I have visitors.

Fortunately I knew that the correct format is
<script type="text/javascript" src="../scripts/name-of-script.js"></script>

I had used your second example on a couple of pages as the original script contained < which the validator objected to.

Thanks again.

pyro
12-06-2003, 06:26 PM
Happy to help. :)

pyro
12-12-2003, 11:31 AM
Cripes... I was just looking at this thread again and I screwwed up that code something awful.

This is what you want:

<script type="text/javascript">
//<![CDATA[
//your script here
//]]>
</script>