-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpushstate-anchor.html
4 lines (4 loc) · 988 Bytes
/
pushstate-anchor.html
1
2
3
4
<!-- Copyright (C) 2014 Erik Ringsmuth - MIT license -->
<script type="text/javascript">
!function(){function t(t){if(!t.ctrlKey&&!t.metaKey&&2!==t.which&&3!==t.which){var e=this.getAttribute("href");if(e&&(0!==e.indexOf("http")||window.location.host===new URL(e).host)){window.history.pushState(JSON.parse(this.getAttribute("state"))||window.history.state,this.getAttribute("title"),e);try{var i=new PopStateEvent("popstate",{bubbles:!1,cancelable:!1,state:window.history.state});"dispatchEvent_"in window?window.dispatchEvent_(i):window.dispatchEvent(i)}catch(t){var n=document.createEvent("CustomEvent");n.initCustomEvent("popstate",!1,!1,{state:window.history.state}),window.dispatchEvent(n)}t.preventDefault()}}}var e=Object.create(HTMLAnchorElement.prototype);e.attachedCallback=function(){this.addEventListener("click",t,!1)},e.detachedCallback=function(){this.removeEventListener("click",t,!1)},document.registerElement("pushstate-anchor",{prototype:e,extends:"a"})}();
</script>