Forum Moderators: open
I have decided to take the plunge and start serving them as application/xhtml+xml.
To do this I need to make many changes. One of these changes involves
a piece of javascript that is used on every single page. It prints out a
copyright notice using document.write .... so that the copyright date is
always the current year:
function copy() {
var thetime=new Date();
var nyear=thetime.getYear();
if (nyear<=99)
nyear= "19"+nyear;
if ((nyear>99) && (nyear<2000))
nyear+=1900;
document.write('copyright © ' + nyear+' domain.com <a href="foo.htm">all rights reserved</a>');
}
True xhtml documents served with the application/xhtml+xml MIME type
are not allowed to use document.write. So this script is obsolete.
What I need to use in the place of doucument.write is document.createElementNS.
Anyone know how to make my copy() script work for xml?
You don't need to create an element, just put one there and fill it later:
JS-----------------------------------------
function setCopyYear()
{
var year = new Date().getYear();
year = year<2000? year+=1900 : year;
document.getElementById('copyYear')
.appendChild(document.createTextNode(year));
}HTML--------------------------------------
<p>copyright © <span id="copyYear"></span> domain.com <a href="foo.htm">all rights reserved</a></p>
<!--
Put script block after element,
(..or call the script after window has loaded)
-->
<script type="text/javascript">
setCopyYear()
</script>
Now, if I wanted to add more text to that (other than just the date) how would I go about that?
I'm thinking along the lines of my origianl script which printed out the site name and a link to a copyright notice.
Thankyou in advance. (I must get round to learning this stuff one day, so I don't need to beg for help lol)