Click to See Complete Forum and Search --> : BACK Button
amacfarl
10-03-2003, 06:25 PM
Folks,
Quickie - I want to have a button on my page that does exactly what the back button does in the browser.
How do I achieve this?
Thanks in advance
Kind regards
Angus
<a href="#" onClick="history.go(-1); return false;">Go back</a>
[J]ona
neil9999
10-04-2003, 02:47 AM
If you wan't a button, use:
<button onClick="history.go(-1)">Go back</button>
Originally posted by neil9999
If you wan't a button, use:
<button onClick="history.go(-1)">Go back</button>
Since the only purpose of that button would be for JavaScript, you would place it with JavaScript, so that those without JavaScript won't see just a button sitting there that doesn't do anything.
document.write('<button onclick="history.go(-1);">Go back</button>');
[J]ona
neil9999
10-06-2003, 10:58 AM
Brilliant idea!
Neil
Always keep that in mind, and you should have no problems. :)
[J]ona
Actually, you also need to keep in mind that you need to provide alternate functionality. Is there a different link you provide for you JavaScript free users? (Might not be relavant in this case, just trying to point it out as a general guideline).
neil9999
10-06-2003, 12:25 PM
Why not just have a message in a table cell with a message, something like 'Click back button in browser', and then with javascript put <body onload="document.getElementById('backbuttoncell').innerHTML='<button onClick="history.go(-1)">Go back</button>';">
This way, if a user have javascript enabled, they see a back button, if they don't they see the message.
Neil
This might be easier:
<script type="text/javascript">
document.write('<button onclick="history.go(-1);">Go back</button>');
</script>
<noscript>
<p>Click the browser's back button to go back, or <a href="index.htm">here</a> to go home</p>
</noscript>
Originally posted by pyro
...Just trying to point it out as a general guideline...
From the W3C Web Content Accessibility Guidelines 1.0 at http://www.w3.org/TR/WCAG10/#gl-new-technologies
Guideline 6. Ensure that pages featuring new technologies transform gracefully.
Ensure that pages are accessible even when newer technologies are not supported or are turned off.
Although content developers are encouraged to use new technologies that solve problems raised by existing technologies, they should know how to make their pages still work with older browsers and people who choose to turn off features.
I thought it appropriate to include a quote from the W3C; when you mentioned "general guideline," it made me think of it.
[J]ona
amacfarl
10-07-2003, 08:54 AM
THANKS FOR ALL THE REPLIES.
The message above is that folk can have JavaScript Switched off.
Is this something that I should be seriously concious off when developing my web site....
If this is the case.... why does anyone do form validation in Javascript and it can be simply switched off
Kind regards
Angus
.... why does anyone do form validation in Javascript and it can be simply switched off
Kind regards
Angus
...that is why all well-written server-side form processing scripts redundantly validate as well...if JavaScript is disabled, server-side validation still occurs...if JavaScript is enabled, then the server-side response load is reduced by validating at the client-side
Originally posted by amacfarl
Is this something that I should be seriously concious off when developing my web site....Yes, definitely. Using a site that relies on JavaScript (for essential elements, such as navigation) will result in an inaccessable site. What you should do is make a site that is fully function (and uses valid HTML 4.01 or XHTML) and then add any JavaScripts as "extras" -- so they don't make you page break when the viewer does not have JavaScript enabled.
I usually have a habit of using JavaScript form-validation primarily to remind the user if he forgets to fill in a form field (as I have a habit of doing quite commonly, myself :rolleyes: ).
[J]ona
amacfarl
10-07-2003, 02:47 PM
ouch!! big big big OUCH!!!
this means that I have a lot of work ahead of me. I have used javascript heavily.
First problem.... I have a login form that has an image that upon the user clicking on it - it submits the form.
i.e. <a href="javascript:logOn()"><img src="Images/tick.jpg" width="20" height="20"></a>
Any ideas how I can overcome this?
It applies to a lot of things... everything - popup windows and all.....
This essentially means that I should only use javascript to "enhance" my web page, however for any that is required on a functional basis I should not use javascript at all !
Help and direction would be appreciated - BIG BIG OUCH!
<input type="image" src="the_image_button.gif">
[J]ona
A lot of the functionality aspects of JavaScript can be done in PHP (or other server-side langages). Form validation is one example (though as Jona said, you may want to do it client side, as well). Another would be your original question. You could make a back button with PHP like this:
<a href="<?PHP echo $_SERVER['HTTP_REFERER']; ?>">Back</a>