anchor-fragment-form-submit-withpath.html (1304B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org"> 4 <link rel="help" href="https://html.spec.whatwg.org/C/#following-hyperlinks"> 5 <title>Anchor element with onclick form submission and href to fragment</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <!-- When an anchor element has an onclick handler which submits a form, 10 the anchor's navigation should occur instead of the form's navigation. 11 However, if the anchor has an href which is just a fragment like "#", 12 then the form should be submitted. Many sites rely on this behavior. --> 13 14 <iframe name="test"></iframe> 15 <form target="test" action="resources/form.html"></form> 16 <a id="anchor" target="test" onclick="document.forms[0].submit()">Test</a> 17 18 <script> 19 async_test(t => { 20 const iframe = document.querySelector('iframe'); 21 iframe.onload = t.step_func(() => { 22 const anchor = document.getElementById('anchor'); 23 anchor.href = '/#'; 24 anchor.click(); 25 window.onmessage = t.step_func(event => { 26 if (typeof event.data === 'string' && event.data.includes('navigation')) { 27 assert_equals(event.data, 'form navigation'); 28 t.done(); 29 } 30 }); 31 }); 32 33 iframe.src = '/'; 34 }); 35 </script>