Redirect to another url when back button is clicked using javascript

后端 未结 4 1779
野趣味
野趣味 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: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
        }
    }
    

提交回复
热议问题