How to remove prompt on unload event using javascript

。_饼干妹妹 提交于 2019-12-01 10:46:54

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);
            }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!