Redirect to another url when back button is clicked using javascript

后端 未结 4 1769
野趣味
野趣味 2020-12-28 11:14

I have a payment form in which user can enter all his card details,and when he clicks,he is taken to the banks 3D secure page. But,the problem is, the user can simply click

相关标签:
4条回答
  • 2020-12-28 11:40

    You can use Brooke's modified script. That's a long script (should be used as external file). You can download it here!

    Then use the script like this:

    bajb_backdetect.OnBack = function(){
        document.location.href = 'http://google.com';
    }
    
    0 讨论(0)
  • 2020-12-28 11:41

    If user clicked back button this will redirect you to your specified page (100% Working)

    window.history.pushState({page: 1}, "", "");
    
    window.onpopstate = function(event) {
        if(event){
            window.location.href = 'https://www.google.com/';
            // Code to handle back button or prevent from navigation
        }
    }
    
    0 讨论(0)
  • 2020-12-28 11:43

    Use the below jquery for redirect your own url when clicking browser back button andipedia.com

       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.example.com';
                    return false;
                }
              }
            });
    
            window.history.pushState('forward', null, './#forward');
          }
    
        });
    
    0 讨论(0)
  • 2020-12-28 11:49

    You have to use history api, and for better compatibility use history.js plugin.

    Handling pressing back button :

    $(window).bind('onpopstate', function(e){
       //your dark doings here
    });
    
    0 讨论(0)
提交回复
热议问题