How do I stop the Back and Refresh buttons from resubmitting my form?

后端 未结 13 1173
时光说笑
时光说笑 2020-11-27 15:16

I am doing web development.

I have a page to do with credit card, which when user click \"refresh\" or \"Back\", the transaction will be performed one more time, wh

相关标签:
13条回答
  • 2020-11-27 15:51

    This code works for not back from current page me..

    Here I put a code which helps you , not open contextmenu and on browser reload ask you leave a page or not...

    I am trying the ask click on browser back button

    jQuery( document ).ready(function() {
    
        document.onkeydown = fkey;
        document.onkeypress = fkey
        document.onkeyup = fkey;
    
        var wasPressed = false;
    
        function fkey(e){
            e = e || window.event;
            //alert(e.keyCode);
            if( wasPressed ) return; 
    
    
            if (e.keyCode == 116 || e.keyCode == 8 || e.keyCode == 17) {
                         // alert("f5 pressed");
                          window.onbeforeunload = null;
                          return true;
                     }
    
        }
    window.onbeforeunload = function (event) {
        var message = ''; // Type message here
    
        if (typeof event == 'undefined') {
            event = window.event;
        }
        if (event) {
            event.returnValue = message;
        }
    
        return message;
    };
    
    jQuery(function () {
    
        jQuery("a").click(function () {
            window.onbeforeunload = null;
        });
    
        jQuery(".btn").click(function () {
            window.onbeforeunload = null;
        });
    
        //Disable part of page
        $(document).on("contextmenu",function(e){
            return false;
        });
    });});
    

    Thanks,

    0 讨论(0)
提交回复
热议问题