Presentation is loading. Please wait.

Presentation is loading. Please wait.

Why Isn't This Button Working? JavaScript and Accessibility in Web Development.

Similar presentations


Presentation on theme: "Why Isn't This Button Working? JavaScript and Accessibility in Web Development."— Presentation transcript:

1 Why Isn't This Button Working? JavaScript and Accessibility in Web Development

2 About Me Name: Steven Tomcavage Email: stomcava@law.upenn.edustomcava@law.upenn.edu School: University of Pennsylvania Law School Job: Web Applications Developer 10+ years experience developing web applications using Perl CGI, Java servlets, XML/XSLT, ColdFusion, and JavaScript

3 Today is all about programming… Comic from Foxtrot by Bill Amend: http://www.foxtrot.com/http://www.foxtrot.com/

4 …specifically JavaScript programming Client-side scripting language Embedded in most browsers Used to make single web pages “interactive” An extra layer on top of HTML and CSS

5 Accessible JavaScript “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.” Tim Berners Lee, W3C Director and inventor of the World Wide Web

6 JavaScript Accessibility Roadmap What is JavaScript accessibility? Why should I care about JavaScript accessibility? What happens if I don’t use accessible JavaScript? How can I make my JavaScript accessible?

7 What is Accessible JavaScript? Device independent Doesn’t block information Doesn’t break expectations W3C’s Web Content Accessibility Guidelines (WCAG) 2.0 W3C’s Mobile Web Best Practices 1.0

8 Why should I care about JavaScript Accessibility? SEO – Google’s spider does not support JavaScript Mobile browsers have limited JavaScript – http://quirksmode.org/m/table.html http://quirksmode.org/m/table.html Assistive technologies limit JavaScript – User browsing via keyboard – Screen readers Section 508 of the Rehabilitation Act – Requires accessible JavaScript for US Government

9 Section 508 on JavaScript (l): When pages utilize scripting languages to display content, or to create interface elements, the information provided by the script shall be identified with functional text that can be read by assistive technology. (n): When electronic forms are designed to be completed on- line, the form shall allow people using assistive technology to access the information, field elements, and functionality required for completion and submission of the form, including all directions and cues. (p): When a timed response is required, the user shall be alerted and given sufficient time to indicate more time is required.

10 Who’s Browsing without JavaScript? DateJavaScript OnJavaScript Off January 200895%5% January 200794%6% January 200690%10% January 200589%11% January 200492%8% January 200389% 11% January 200288%12% January 200181%19% January 200080%20% Data from http://w3schools.com/browsers/browsers_stats.asphttp://w3schools.com/browsers/browsers_stats.asp

11 What happens if I don’t make my JavaScript accessible? 1.Disable JavaScript in your browser: – In Chrome, click the Tool icon at the top right, then go to Options -> Under the Hood -> Content Settings -> JavaScript and check “Do not allow any site to run JavaScript” – In Firefox, go to Tools -> Options -> Content and uncheck “Enable JavaScript” – In IE 7 or IE 8, go to Tools -> Internet Options -> Security -> Custom Level and under Scripting, check “Disable” and restart browser – In Safari, go to Safari -> Preferences -> Security and uncheck “Enable JavaScript”

12 What happens if I don’t make my JavaScript accessible? (cont.) 2.Load http://benjerry.com and click “Halloween” (?)http://benjerry.com 3.Load http://reader.google.com and loginhttp://reader.google.com 4.Load http://www.apple.com/safari/download/ and click the “Download” buttonhttp://www.apple.com/safari/download/ 5.What happens?

13 How can I make my JavaScript accessible? Easy Events – onClick and onDblClick Events – onMouseOver and onMouseOutEvents – onChange and onSubmitDHTMLAJAX interactions Hard Tabs and other widgets

14 1. Events – onClick and onDblClick What are they?JavaScript event handlers which are triggered after mouse click(s) Who do they affect?Users browsing by keyboard Problems? Breaks web page expectations Sometimes replaces href target How to fix Provide a working link or button Don’t use Example https://www.law.upenn.edu/cf/its/cali/js1.cfm

15 1. Events – onClick and onDblClick Inaccessible JavaScript 1. 2. function showError() { 3. document.getElementById('errorMsg').style.display = 'block'; 4. return false; 5. } 6. function hideError() { 7. document.getElementById('errorMsg').style.display = 'none'; 8. return false; 9. } 10. 11.<a href="javascript:void(0);" onclick="return showError();" 12. onDblClick="return hideError();"> 13. Click once to see the error message, twice to make it go away 14. 15. 16. An error has occurred! 17.

16 1. Events – onClick and onDblClick Accessible JavaScript 1. 2. function showHide() { 3. var e = document.getElementById('errorMsg2'); 4. if (e.style.display == 'block') { 5. e.style.display = 'none'; 6. } 7. else { 8. e.style.display = 'block'; 9. } 10. return false; 11. } 12. 13. 14. Click once to see the error message, and again to make it go away 15. 16. 17. An error has occurred! 18.

17 2. Events – onMouseOver and onMouseOut What are they?JavaScript event handlers used to create drop-down menus, pop-up windows, and hover-over effects Who do they affect?Touch devices and keyboard users Problems?Data on page is not visible How to fix Links with hrefs for menus Hidden links for pop-ups CSS to create hover effects Example https://www.law.upenn.edu/cf/its/cali/js2.cfm

18 2. Events – onMouseOver & onMouseOut Inaccessible JavaScript 1. 2. function showSubmenu() { 3. document.getElementById('submenu').style.display='block'; 4. } 5. function hideSubmenu() { 6. document.getElementById('submenu').style.display='none'; 7. } 8. 9. 10. Item Without Submenu 11. 12. <div onMouseOver="showSubmenu();" 13. onMouseOut="hideSubmenu();">Item WithSubmenu 14. 15. 16. Submenu Item 1 17. Submenu Item 2 18. 19. 20. 21.

19 2. Events – onMouseOver & onMouseOut Accessible JavaScript 1. 2. function showSubmenu2() { 3. document.getElementById('submenu2').style.display='block'; 4. } 5. function hideSubmenu2() { 6. document.getElementById('submenu2').style.display='none'; 7. } 8. 9. 10. Item Without Submenu 11. 12. 13. Item With Submenu 14. 15. 16. 17. Submenu Item 1 18. Submenu Item 2 19. 20. 21. 22.

20 3. Events – onChange and onSubmit What are they?JavaScript event handlers used to customize forms on the fly Who do they affect?Users without JavaScript Problems? Cascading select boxes Optional form questions How to fix Submit partial form to simulate dynamic form actions Duplicate validation on server Ensure submits Example https://www.law.upenn.edu/cf/its/cali/js3.cfm

21 3. Events – onChange and onSubmit Inaccessbile JavaScript 1. 2. function autoEnterAddress() { 3. var s = document.getElementById('ship_address'); 4. var b = document.getElementById('bill_address'); 5. if (document.getElementById('ship_eq_bill').checked) { b.value = s.value; } 6. else { b.value = ''; } 7. } 8. function processForm() { 9. var s = document.getElementById('ship_address'); 10. var b = document.getElementById('bill_address'); 11. var isValid = true; 12. if (document.getElementById('ship_eq_bill').checked) { 13. if (b.value != s.value) { 14. alert("Your shipping and billing addresses are different!"); 15. isValid = false; 16. } 17. } 18. return isValid; 19. } 20. 21. 22. Shipping Address 23. Address: 24. Billing Address 25. My billing address is the same as my shipping address 26. 27. Address: 28. 29.

22 3. Events – onChange and onSubmit Accessible JavaScript 1. 2. var billEqShip = "#iif(form.ship_address2 eq form.bill_address2, de('true'), de('false'))#"; 3. function autoEnterAddress2() { 4. var s = document.getElementById('ship_address2'); 5. var b = document.getElementById('bill_address2'); 6. b.value = s.value; 7. billEqShip = true; 8. } 9. function processForm2() { 10. var s = document.getElementById('ship_address2'); 11. var b = document.getElementById('bill_address2'); 12. var isValid = true; 13. if (billEqShip && b.value != s.value) { 14. alert("Your shipping and billing addresses are different!"); 15. isValid = false; 16. } 17. return isValid; 18. } 19. 20. 21. Shipping Address 22. Address: 23. Billing Address 24. 25. Address: 26. 27.

23 4. DHTML What is it?Dynamic HTML uses JavaScript events to manipulate DOM Who does it affect?Users without JavaScript Problems?Data is not retrievable How to fix Use CSS for rollover effects Use CSS to hide data Add a link or button to get data Example https://www.law.upenn.edu/cf/its/cali/js4.cfm

24 4. DHTML Inaccessible JavaScript 1. 2. function showExample() { 3. d = document.getElementById("showHide"); 4. e = == 'ndocument.getElementById("example"); 5. if (e.style.display one') { 6. e.style.display = 'block'; 7. d.innerHTML = 'Hide example'; 8. } 9. else { 10. e.style.display = 'none'; 11. d.innerHTML = 'Show example'; 12. } 13. } 14. 15. Show example 16. This is the example. 17.<div id="colorChange" 18. onMouseOver="this.style.color='red'“ 19. onMouseOut="this.style.color='black'"> 20. Rollover to change color 21.

25 4. DHTML Accessible JavaScript 1. ##colorChange:hover { color: red; } 2. 3. function showExample2() { 4. d = document.getElementById("showHide2"); 5. e = document.getElementById("example2"); 6. if (e.style.display == 'none') { 7. e.style.display = 'block'; 8. d.innerHTML = 'Hide example'; 9. } 10. else { 11. e.style.display = 'none'; 12. d.innerHTML = 'Show example'; 13. } 14. } 15. 16. 17. <a href="js4.cfm?example=hide" id="showHide2“ 18. onmouseover="javascript:showExample2();“ 19. onmouseout="javascript:showExample2();">Show example 20. 21. This is the example. 22. Rollover to change color

26 5. AJAX Interactions What is it?Asynchronous JavaScript and XML, used to submit refresh small portions of a page Who does it affect?Screen readers and web spiders Problems?User is unable to retrieve all the data from the page How to fixCall asyncronous code from JavaScript AJAX and from HTML forms and links Example https://www.law.upenn.edu/cf/its/cali/js5.cfm

27 5. AJAX Interactions Inaccessible JavaScript 1. 2. $(document).ready( function() { 3. $("input#myButton").click(function() { 4. $.get( 5. 'js5ajax.cfm', 6. {json: true}, 7. function(data) { 8. $('.result').html(data); 9. alert('Load was performed.'); 10. } 11. ); 12. }); 13. }); 14. 15. Click this button to load the data: 16. 17.

28 5. AJAX Interactions Accessible JavaScript 1. 2. $(document).ready( function() { 3. $("form").submit(function() { 4. $.get( 5. 'js5ajax.cfm', 6. {json: true}, 7. function(data) { 8. $('.result2').html(data); 9. alert('Load was performed.'); 10. } 11. ); 12. return false; 13. }); 14. }); 15. 16. Click this button to load the data: 17. 18. 19. 20. Or click here to load the data: 21.

29 6. Tabs and Other Widgets What are they?Tabs and widgets are page layouts that rely on DHTML and/or AJAX Who do they affect?Anyone with limited or missing JavaScript Problems? Data is not available Pages may not load How to fix https://courses.law.upenn.edu

30 Tools for JavaScript Development NoScript plugin for Firefox Firebug plugin for Firefox and Chrome Web Developer Toolbar plugin for Firefox Built-in Developer Tools for Chrome IE Developer Tools for IE 8 and above jQuery for writing valid cross-brower JavaScript that degrades well

31 What do I need to Remember? Build initial site without JavaScript JavaScript at the end of development Avoid using “javascript:void(0)” Keep code that might be called asynchronously separate to ease AJAX Limit your use of Validate on both client and server Test site without JavaScript

32 Questions? Email: stomcava@law.upenn.edustomcava@law.upenn.edu


Download ppt "Why Isn't This Button Working? JavaScript and Accessibility in Web Development."

Similar presentations


Ads by Google