In this tutorial we will learn how to disable back button in browser using jQuery.
Here we will use window.history.pushState for restrict back button of browser in jQuery.
let's see the example -
How to disable back button in browser using jQuery
<!DOCTYPE html>
<html>
<head>
<title>Disable Back Button in Browser Using jQuery</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<button>click on browser back button</button>
<script type="text/javascript">
$(document).ready(function () {
window.history.pushState(null, "", window.location.href);
window.onpopstate = function () {
window.history.pushState(null, "", window.location.href);
};
});
</script>
</body>
</html>