Click to See Complete Forum and Search --> : Back button code problem


kbesseling
05-03-2003, 12:25 PM
I picked up the following code from the JavaScript Source webpage:

<a href="#" onClick="history.go(-1)">Back</a>

I then checked the syntax in BBEdit, and it said:

Document type doesn't permit attribute “onClick” within element “<a>”.

The document type is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">

Can anybody explain why I get this message, and what to do about it?

Charles
05-03-2003, 12:31 PM
XHTML is case sensitive and the attribute name is, and always was, onclick. And you have another problem as well. Your link will do absolutely nothing for one in ten users. To avoid looking silly try instead:

<script type="text/javascript">
<!--
document.write('<a href="#">Get Back Jo Jo</a>');
document.links[document.links.lenght-1].onclick = function () {history.back()};
// -->
</script>