| <!DOCTYPE html> |
| <html> |
| <head> |
| <title> W3C DOM Level 3 Event Object Property: defaultPrevented </title> |
| <script type="text/javascript"> |
| var PassTest = function() |
| { |
| document.getElementById("testresult").firstChild.data = "PASS"; |
| } |
| |
| var FailTest = function() |
| { |
| document.getElementById("testresult").firstChild.data = "FAIL"; |
| } |
| |
| var EVENT = "click"; |
| var TARGET; |
| |
| window.onload = function() |
| { |
| try |
| { |
| TARGET = document.getElementById("target"); |
| TARGET.addEventListener(EVENT, TestCapture, true); |
| } |
| catch(ex) |
| { |
| FailTest(); |
| } |
| } |
| |
| function TestCapture(evt) |
| { |
| try |
| { |
| evt.preventDefault(); |
| |
| if ((evt.type == EVENT) && (evt.defaultPrevented == true)) |
| { |
| PassTest(); |
| } |
| else |
| { |
| FailTest(); |
| } |
| } |
| catch(ex) |
| { |
| FailTest(); |
| } |
| } |
| </script> |
| </head> |
| <body> |
| <h4> |
| Test Description: |
| Event listeners can cancel default actions of cancelable event objects by invoking the Event.preventDefault() |
| method, and determine whether an event has been canceled through the Event.defaultPrevented attribute. |
| </h4> |
| |
| Click the hyperlink: |
| <a href="http://samples.msdn.microsoft.com/ietestcenter/" id="target">http://samples.msdn.microsoft.com/ietestcenter</a> |
| |
| <p>Test passes if the word "PASS" appears below after clicking the hyperlink and the page does not navigate away.</p> |
| <div>Test result: </div> |
| <div id='testresult'>FAIL</div> |
| </body> |
| </html> |