UNPKG

prevent-back

Version:

Prevent vistor go back to previous page

2 lines (1 loc) 848 B
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).preventBack={})}(this,(function(e){"use strict";var t=window,n=t.document,o=t.history,i="isPreventState",f=["touchstart","click","keydown","keyup"],r=function(){var e;return null===(e=o.state)||void 0===e?void 0:e[i]};function d(){r()||o.pushState({[i]:!0},n.title)}var u=d,a=function(){o.back()};e.default=function(e){!function(){for(var e=function e(){if(d(),r())for(var t=0;t<f.length;t++){var n=f[t];window.removeEventListener(n,e)}},t=0;t<f.length;t++){var n=f[t];window.addEventListener(n,e)}}(),function(e){window.addEventListener("popstate",(function(){r()||e(u,a)}))}(e)},e.leave=a,e.stay=u,Object.defineProperty(e,"__esModule",{value:!0})}));