auto-expand-details-text-fragment.html (896B)
1 <!DOCTYPE html> 2 <script src="/scroll-to-text-fragment/stash.js"></script> 3 4 <!-- This test is navigated to with the fragment #:~:text=foo --> 5 6 <body> 7 <div style="height: 4000px;">spacer</div> 8 <details> 9 <div>foo</div> 10 </details> 11 <script> 12 const details = document.querySelector("details"); 13 details.ontoggle = () => { 14 const results = {}; 15 // This should be true. The details element should be opened by 16 // ScrollToTextFragment because it has matching text. 17 results.detailsHasOpenAttribute = document.querySelector('details').hasAttribute('open'); 18 // This should be greater than zero. The page should be scrolled down 19 // to the matching target. 20 results.pageYOffsetAfterRaf = window.pageYOffset; 21 22 params = new URLSearchParams(window.location.search); 23 stashResultsThenClose(params.get('key'), results); 24 }; 25 </script> 26 </body>