PDA

View Full Version : history.back() onclick with DOM


_com
09-22-2005, 08:30 PM
I need a hand with a DOM script. Thanks for any help in advance.

Have a slideshow navigation and want to put a DOM onubtrusive JS that finds
the <a> in <li id="nav-back">and executes history.back() with a onclick handler. No worry about JS disabled because then I use a other link that is hidden when JS is enabled ...

Some questions-ideas

What do i need to put in the <a href="??"> of <li id="nav-back"> ?
And the script I started see below, should it be written like that ??
History.back() works perfectly cross-browser in DOM capable browsers ??

This is the HTML

<div id="navwrap">
<ul id="nav">
<li id="nav-prev"><a href="#" title="go to previous image">previous</a></li>
<li id="nav-back"><a href="#" title="go to overview of images">back to overview</a></li>
<li id="nav-forward"><a href="#" title="go to next image">next</a></li>
</ul>
</div>

Is this how to do go about it
if (!document.getElementbyId) {return;}
var backButton = document.getElementbyId('nav-back').document.getElementBytagname('a')

backButton.onclick = history.back();
}

Is it possible to show in the title tag that last history entry ?

felgall
09-22-2005, 11:11 PM
var backButton = document.getElementbyId('nav-back').document.getElementBytagname('a')

doesn't make any sense, try this instead

var backButton = document.getElementbyId('nav-back').parent;

glenngv
09-23-2005, 07:47 AM
Check the javascript console, you had so many syntax errors.
var backButton = document.getElementById('nav-back').getElementsByTagName('a')[0];
backButton.onclick = function(){ history.back(); return false; }