Forum Moderators: open
The W3C [w3.org] says:
6.3 Ensure that pages are usable when scripts, applets, or other programmatic objects are turned off or not supported. If this is not possible, provide equivalent information on an alternative accessible page. [Priority 1]
For example, ensure that links that trigger scripts work when scripts are turned off or not supported (e.g., do not use "javascript:" as the link target). If it is not possible to make the page usable without scripts, provide a text equivalent with the NOSCRIPT element, or use a server-side script instead of a client-side script, or provide an alternative accessible page as per checkpoint 11.4. Refer also to guideline 1.
Techniques for checkpoint 6.3
Sure could use a usability/accessibility section here, couldn't we?
*****
Eg:
To visit page2.asp, you are most likely to have to go through home.asp to get there, so do.
<script>
<!--
document.write("<a href=history.go(-1)>Back</a>");
//-->
</script>
<noscript>
<a href="home.asp">Back</a>
</noscript>
*****
That's what I would do but if that's not your scenario then just link to home.
So far, I've not been able to get rid of the "javascript" in "javascript:history.go(-1)". How do you get the link to work without it?
This return link appears after a form is successfully filled in. There may be several attempts before the process is successful, so I have a counter to keep track of the number of times the processing page is redrawn.
This code appears at the top of the page in php:
// define return link options for success page
$returnlink = "<script type='text/javascript'>
//<![CDATA[
window.document.write('<p>Return to <a href=\"javascript:history.go(" . $_POST['historyCounter'] . ");\">last page visited<\/a><\/p>');
//]]>
</script>
<noscript><p>Return to <a href='/'>Home</a></p></noscript>";
Then in my page when I want to show the link I just put
<?php
echo $returnlink;
?>
It works and w3.org's html validator accepts it. The W3 .org's link validator [validator.w3.org] almost goes for it. Here's what it reports:
javascript:history.go(-1);
What to do: You must change this link: people using a browser without JavaScript support will not be able to follow this link. See the Web Content Accessibility Guidelines on the use of scripting on the Web and the techniques on how to solve this.
Response status code: 501
Response message: Protocol scheme 'javascript' is not supported(and on the 501 status code: "Could not check this link: method not implemented or scheme not supported")
Since I've given a <noscript> option, I'm guessing that I'm okay using javascript:history.go(-1);
Does that make sense to you all?
of course if cookies are off then it doesn't work using cookies but then they need cookies enabled to use my sites anyway.
So far, I've only got one page that needs php in this site, so it struck me as overkill to make every page go through php interpretation just to remember where the user was. But maybe not.
Are there other things you do with asp/php on what seem like otherwise normal pages (not needing asp/php coding)?
The problem with
javascript: links is that they do nothing if Javascript is disabled. To be compliant, all you need to do is to provide a straight href link overridden by the Javascript if available: <a href="home.asp" [b]onclick="history.go(-1);return false;"[/b]>
Yours would be a much simpler solution and it gets rid of the "javascript:" part. The validators like it, and don't even seem to notice the "onclick".
I'd use it, except that labeling the link becomes very difficult. (I'm open to suggestions!) I don't want to say "return to previous page" because it might go to the home page. Unless there's a way to label the link accurately it becomes a "Go somewhere" link.