Detect Browser Back Button jQuery Plugin – jquery.backDetect.js
Determining when a user clicks their browser’s back button has never been easier with this jQuery plugin. With a quick easy install and minimal set up work you’ll be firing callback functions on back button declarations in no time. You can fire some action or show alert while back button click detected.
Libraries
Include jquery latest library with jquery.backDetect.js
library on page.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script type="text/javascript" src="jquery.backDetect.js"></script> |
Basic Usage
Display alert when click browser back button.
<script> $(window).load(function(){ $('body').backDetect(function(){ alert("Look forward to the future, not the past!"); }); }); </script> |
Custom Options
You can set a delay intiate the back detect. Very similar to setting the time in setTimeout:
The length of time it takes for the backDetect plugin to fire and monitor when a user hits the back button.
$(window).load(function(){ $('body').backDetect(function(){ alert("Look forward to the future, not the past!"); }); }, 1000); |
See live demo and download source code.
DEMO | DOWNLOAD
This awesome script developed by ianrogren, Visit their official github repository for more information and follow for future updates.