prevent-popstate-scroll
history.scrollRestoration
and its polyfill instead, it has broader compatibility.
Deprecated: use Prevent the scroll restoration caused by the
popstate
event or back/forward buttons. Demo
Warning: currently only working on Chrome and Safari. Firefox and IE will need a bit more work.
Usage
// Prevent the scroll, alwayspreventPopstateScroll; // Stop preventing the scrollpreventPopstateScroll; // Prevent the scroll only once, for example before manually calling history.go(-1)preventPopstateScroll;
With browserify
npm install --save prevent-popstate-scroll
var preventPopstateScroll = ;
Alternative usage in ES6
; ;;;
or:
; ;;
API
preventPopstateScroll.prevent()
Prevents the scroll restoration that normally happens after the popstate
History event.
preventPopstateScroll.allow()
Restores the normal browser behavior.
preventPopstateScroll.preventOnce()
Prevents the scroll restoration only once. Useful before manipulating the history once (e.g. history.go(-1)
), without changing the whole site's behavior.
Dependencies
Used on
- http://away.gorving.com/ — to avoid scroll jumping when closing history-enabled lightboxes (i.e. closable via back button)
License
MIT © Federico Brigante