Ah, Javascript. The wonderful scripting language that creates lots of cool stuff on your web page. But how do you make it Accessible?
Links:
- W3C Checkpoint 6.3
- Directly Accessible Scripts (W3C)
- DOM Overview (W3C)
- WaSP Javascript Manefesto
- Creating Accessible JavaScript
- (WebAim)
This is an example of a javascript “listener” which opens a link in a new window (using a function) if the rel
in the a
tag is “external”.
window.onload=function(){
setOnClick();
}
function setOnClick() {
if(!document.getElementsByTagName) {
return;
}
var anchors = document.getElementsByTagName("a");
for (var i=anchors.length; i !=0; i--) {
var a=anchors[i-1];
if (a.rel.indexOf("external") != -1) {
a.onclick = function(){newWin(this.href,'popup1',700,400);
return false;}
}
}
3 replies on “Unobtrusive Javacript (and the DOM)”
Author’s Note: Another way to avoid javascript ‘problems’ is to use server-side scripting for form validation, if possible.
In this podcast you told us to use the lang attribute in the body tag. The lang attribute has been removed in the XHTML 1.1 Strict specification. I read that today before listening to your podcast. Just FYI.
Look at the changes in the Specification
http://www.w3.org/TR/xhtml11/changes.html
I, initially think, that this concept of Unobtrusive Javascript is great idea, but I need to investigate it more to figure out how I can use it in web design.
Thanks for the great shows Den!
Thank you for the clarification, Micah. I believe the code for XHTML should actually be like this: