prevent-back
Version:
Prevent vistor go back to previous page
2 lines (1 loc) • 571 B
JavaScript
var t=window,n=t.document,e=t.history,i=["touchstart","click","keydown","keyup"],o=function(){var t;return null===(t=e.state)||void 0===t?void 0:t.isPreventState};function r(){o()||e.pushState({isPreventState:!0},n.title)}var a=r,u=function(){e.back()};function v(t){!function(){for(var t=function t(){if(r(),o())for(var n=0;n<i.length;n++){var e=i[n];window.removeEventListener(e,t)}},n=0;n<i.length;n++){var e=i[n];window.addEventListener(e,t)}}(),function(t){window.addEventListener("popstate",(function(){o()||t(a,u)}))}(t)}export{v as default,u as leave,a as stay};