开发者

How to remove prompt on unload event using javascript

开发者 https://www.devze.com 2023-03-06 12:59 出处:网络
How can I remove prompt on unload event using javascript? thanks开发者_如何学Go in advance... hm, I don\'t want to show the prompt when firing the custom function for the unlaod event of the body...

How can I remove prompt on unload event using javascript? thanks开发者_如何学Go in advance...

hm, I don't want to show the prompt when firing the custom function for the unlaod event of the body... Is it possible? so here's my code:

window.onbeforeunload = function()
{
    //cancel the unload
            //cancel prompt
}


Make sure your event handler doesn't have a return statement in it. Returning from the function triggers the conformation message.

Update based on the code comments in the edited question: If the user does something to leave the page, then you can tell the browser to ask them if they are sure. You cannot silently prevent them. If the user wishes to leave the page, then they can do so (dodgy sites full of adverts and/or malware would love it to be otherwise, thankfully it isn't)


Most certainly NOT impossible. All you have to do to suppress the prompt is omit the "return" statement. Returning any value will cause the prompt to fire. Example:

           window.onbeforeunload = function saveAllData()
            {
                //Invoke AJAX method to save DataTable in database
                [classname].SaveDataTable();
                //return true;                      //comment out 'return' to suppress prompt
            }

            function SaveDataTable_Callback(response) 
            {
                //alert(response);
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消