onbeforeunload

How to execute ajax function onbeforeunload?

二次信任 提交于 2019-11-26 02:58:40
问题 I\'m developing a php/javascript chat. When the user logs in, his/her username is inserted in a MySQL table called queue . This insert returns the mysql_insert_id() that will be stored in a session variable called $_SESSION[\'CHAT_QUEUE_ID\'] I need the MySQL table row to be deleted when the user closes the page. I tried the following, but without success: js file window.onbeforeunload = closeSession; function closeSession(){ $.ajax({ url: \"/chat/process/chat.php\", type: \"GET\" }); return

How to prevent closing browser window?

天大地大妈咪最大 提交于 2019-11-26 01:49:36
问题 I tried the following code to get an alert upon closing a browser window: window.onbeforeunload = confirmExit; function confirmExit() { return \"You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?\"; } It works, but if the page contains one hyperlink, clicking on that hyperlink raises the same alert. I need to show the alert only when I close the browser window

Prevent a webpage from navigating away using JavaScript

耗尽温柔 提交于 2019-11-26 00:28:18
问题 How to prevent a webpage from navigating away using JavaScript? 回答1: Using onunload only allows you to display messages, but it will not interrupt the navigation (because it is too late). However, you can use onbeforeunload and it will interrupt navigation: window.onbeforeunload = function() { return "Are you sure you want to navigate away?"; } Edit : Removed confirm() in return statement as this caused a confirm window as expected, but also showed a second confirm with the result of the

How can I override the OnBeforeUnload dialog and replace it with my own?

坚强是说给别人听的谎言 提交于 2019-11-25 21:43:21
问题 I need to warn users about unsaved changes before they leave a page (a pretty common problem). window.onbeforeunload=handler This works but it raises a default dialog with an irritating standard message that wraps my own text. I need to either completely replace the standard message, so my text is clear, or (even better) replace the entire dialog with a modal dialog using jQuery. So far I have failed and I haven\'t found anyone else who seems to have an answer. Is it even possible? Javascript