refresh-with-section.sub.html (1010B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <p id="referrer">{{header_or_default(referer, )}}</p> 4 <section id="section">My section</section> 5 <span id="info">Refreshing to</span> 6 <span id=url>{{GET[url]}}</span> 7 <script> 8 function refresh() { 9 if (url.textContent !== "") { 10 const refresh = document.createElement("meta"); 11 refresh.httpEquiv = "refresh"; 12 refresh.content = `0; url=${url.textContent}`; 13 document.documentElement.appendChild(refresh); 14 } else { 15 info.textContent = "Not refreshing."; 16 } 17 } 18 19 function sendData() { 20 const documentReferrer = document.referrer; 21 const data = {referrer: referrer.textContent, documentReferrer, url: location.href}; 22 window.parent.postMessage(data, "*"); 23 } 24 25 const sectionHash = "#section"; 26 if (url.textContent !== sectionHash) { 27 window.addEventListener("hashchange", refresh); 28 location.hash = sectionHash; 29 } else if (location.hash !== sectionHash) { 30 window.addEventListener("hashchange", sendData); 31 refresh(); 32 } else { 33 sendData(); 34 } 35 </script>