Skip to Page Content | Navigation for Module


Navigation for Module 10: Scripts/Java
Page 7 of 19

  1. * Pop-ups

Pop-up Windows Scripting

Because a pop-up window does what it says - pops up an additional window - a user can end up feeling disoriented, not knowing the context of the new information. Most of the accessibility issues presented by pop-up windows, however, stem from the misuse of the A tag. Some developers incorrectly use this tag to trigger events, either by including JavaScript in the href attribute, or by leaving the href tag empty and overriding the onClick event.

Code sample where script is in the link

<HTML>
<!-- This is a bad example!
<SCRIPT language="JavaScript1.1">
function X() {
   alert("Yo");
   window.open('http://www.google.com', "_self");
}
</SCRIPT>
<A href="javascript:X();">Test link</A>
</HTML>

A webpage always needs to remain usable without scripting, but in the code sample above, a scripting call is made directly from the href attribute. Because of this, the page works only for browsers or assistive technologies that are capable of interpreting the script.

The solution is to never call a script from the href attribute. The href should only be used for linking purposes, such as to another web page or file. Instead, you should set the target of the onFocus event to be the script.

Code sample where script triggered by the OnFocus event

<HTML>
<SCRIPT language="JavaScript1.1">
function X() {
   alert("Yo");
   window.open('http://www.google.com', "_self");
}
</SCRIPT>
<A href="http://www.google.com" onFocus="X();return false;">Test link</A>
</HTML>

Coding the event trigger using the function in the above code sample maintains the integrity of the link. Also, the script part relies on the onFocus event, which would only be seen by a script-aware browser. If the browser does not support scripting, then the link could be followed in the normal hypertext way.

Note: Avoid opening up a full-screen window, or opening up a window automatically. These can be difficult for navigation.

The next page will discuss forms and navigation.

Top of Page arrow up
       Page 7


 
-- END OF PAGE