onClick Event Example
onClick: Open new window example (Accessible)
- The
onclickevent handler is directly on theaelement and opens the "World Wide Web Consortium" website in a new window. - This technique is compatible with assistive technologies because the technology knows to simulate the
onClickevent since it is on the same node as theaelement. - To make the link part of the TAB navigation in the browser, use the
hrefattribute and sett the attribute value to "javascript:void(0)".
HTML Example
HTML Source Code
<p><a href="javascript:void(0)" onclick="window.open('http://www.w3.org', '_blank')">World Wide Web Consortium Home in New Window</a></p>
onClick: Parent element problem (Inaccessible)
- The
onclickevent handler is on a parent element and the event opens the "World Wide Web Consortium" website in a new window. - This technique is not compatible with assistive technologies, due to the the
onClickevent being a parent node of the link. Since theonclickevent is not on the link node, assistive technologies do not know to simulate the event. - To make the link part of the TAB navigation in the browser, use the
hrefattribute and set the attribute value to "javascript:void(0)".
HTML Example
HTML Source Code
<p onclick="window.open('http://www.w3.org', '_new')"><a href="javascript:void(0)" >World Wide Web Consortium Home in New Window</a></p>
onClick: Tabindex problems (Inaccessible)
- The
onclickevent handler is directly on theaelement and opens the "World Wide Web Consortium" website in a new window. - To make the link part of the TAB navigation in the browser, the
tabindexattribute is set to "0" and thehrefattribute is not defined. - This technique is not compatible with assistive technologies, due to the use of the
tabindexattribute to make the link part of the TAB order of the page instead of thehrefattribute.
HTML Example
HTML Source Code
<p class="tabindex"><a tabindex="0" onclick="window.open('http://www.w3.org', '_blank')">World Wide Web Consortium Home in New Window</a></p>
CSS Source Code
p.tabindex {
text-decoration: underline;
}
