Redirect to another url when back button is clicked using javascript

Jimmy Wales Reply 17:02
you can try this to redirect your own url when clicking browser back button


<script>
jQuery(document).ready(function($) {

      if (window.history && window.history.pushState) {

        $(window).on('popstate', function() {
          var hashLocation = location.hash;
          var hashSplit = hashLocation.split("#!/");
          var hashName = hashSplit[1];

          if (hashName !== '') {
            var hash = window.location.hash;
            if (hash === '') {
              alert('Back button was pressed.');
                window.location='www.yourweburlhere.com';
                return false;
            }
          }
        });

        window.history.pushState('forward', null, './#forward');
      }

    });
</script>

Related Posts

validation 1265327070078361419
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us