View Full Version : Programming a Back button
wanapitei
02-21-2008, 10:17 PM
Is there simple syntax available to program a "back" button, or is this a complex matter?
Kind regards,
thetestingsite
02-21-2008, 10:22 PM
Something like this:
<input type="button" value="Back" onclick="history.go(-1);">
Hope this helps.
jscheuer1
02-22-2008, 03:32 AM
Not in HTML. But yes, as thetestingsite says, it is pretty simple in javascript, but there are limitations. You cannot get any information about the history, and there are no guarantees that there will be a history to go to, and it requires javascript enabled - those without javascript enabled will get nothing from a button of that sort.
For the vast majority of occasions, this is something best left to the browser - it has a back button right on it.
You could also make it disabled if you haven't had any history yet in that session. Right?
jscheuer1
02-22-2008, 06:52 AM
You could also make it disabled if you haven't had any history yet in that session. Right?
Not really, you can ask for:
history.length
But the precision (+-1) varies with browsers, and once established includes both forward and backward history, so if you were at the start page, with nowhere back to go, but had made 26 forward moves before using back to get back to that page, the length would still be 26, even though there was nowhere back to go.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.