dynamic-href-002.tentative.html (1687B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test dynamic change of the href attribute</title> 6 <link rel="help" href="https://w3c.github.io/mathml-core/#attributes-common-to-html-and-mathml-elements"> 7 <link rel="help" href="https://w3c.github.io/mathml-core/#dom-and-javascript"> 8 <link rel="help" href="https://github.com/w3c/mathml-core/issues/142"> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="/resources/testdriver.js"></script> 12 <script src="/resources/testdriver-vendor.js"></script> 13 </head> 14 <body> 15 <p>To test manually, click the blue rectangle.</p> 16 <p> 17 <math> 18 <mspace width="50px" height="10px" style="background: gray"></mspace> 19 <mrow id="target" href="javascript:badHandler()" style="background: blue"> 20 <mspace width="50px" height="10px"></mspace> 21 </mrow> 22 <mspace width="50px" height="10px" style="background: gray"></mspace> 23 </math> 24 </p> 25 <a id="badTarget" href="javascript:badHandler()">DON'T CLICK ME</a> 26 <script> 27 var t = async_test("Click element with href"); 28 function handler() { t.done(); } 29 function badHandler() { 30 t.step(() => { assert_unreached("Bad handler executed"); }); 31 t.done(); 32 } 33 34 // Modify the href attribute to execute the 'good' handler. 35 let target = document.getElementById("target"); 36 target.setAttribute("href", "javascript:handler()"); 37 38 test_driver.click(target).then(() => { 39 return test_driver.click(document.getElementById("badTarget")); 40 }).catch(() => { 41 t.step(() => { assert_unreached("Click failed"); }); 42 t.done(); 43 }); 44 </script> 45 </body> 46 </html>