tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

anchor-fragment-form-submit.html (1171B)


      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()" href="#">Test</a>
     17 
     18 <script>
     19 async_test(t => {
     20  const anchor = document.getElementById('anchor');
     21  t.step(() => anchor.click());
     22  window.onmessage = t.step_func(event => {
     23    if (typeof event.data === 'string' && event.data.includes('navigation')) {
     24      assert_equals(event.data, 'form navigation');
     25      t.done();
     26    }
     27  });
     28 });
     29 </script>