onbeforeunload

“Are you sure you want to leave this page?” functions for cancel and OK

℡╲_俬逩灬. 提交于 2019-12-01 12:09:11
问题 i'm trying to do something similar to some websites where you leave and it'll display a popup saying "Are you sure you want to leave this page" and with two options saying "Cancel" and "OK". How would I do that and make it so when you click "Cancel" it'll just cancel the box and when they click "OK" it'll do a 'leaveChat();' function and leave the website? I've tried using the onbeforeunload which was working but i'm not sure on the function part. Thanks for the help! 回答1: There is no way to

How to remove prompt on unload event using javascript

。_饼干妹妹 提交于 2019-12-01 10:46:54
How can I remove prompt on unload event using javascript? thanks 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

window.onbeforeunload support in Firefox

风流意气都作罢 提交于 2019-12-01 10:36:33
问题 I am using window.onbeforeunload in my javascript. This works perfectly in IE but is not triggered in Firefox. I checked on different links in stackoverflow.... In it I read that window.onbeforeunload is not supported by firefox. Is this true? If yes, can you please tell me a different way to call app.deleteAccount(key) on close of browser. Here is my javascript. Please look at the deleteFile() and dontDeleteFile() methods. <script type="text/javascript"> //Event handler for body onload

How to remove prompt on unload event using javascript

て烟熏妆下的殇ゞ 提交于 2019-12-01 08:12:52
问题 How can I remove prompt on unload event using javascript? thanks 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 } 回答1: 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

Is it possible to capture the user's answer when using onbeforeunload confirmation?

ぃ、小莉子 提交于 2019-12-01 05:59:16
I need to warn users that they will lose information when leaving a page. This is easily done using the onbeforeunload event. My problem is that I want to take some action if the user decides to leave. Here's an example (I'm using jquery because it's loaded anyway): $(window).on('beforeunload', function(e){ return "Do you really want to leave?"; }); What I would like to do is something like this (this code doesn't work, I know, it's just an example to illustrate what I'm trying to do): $(window).on('beforeunload', function(e){ // Ask for user confirmation var bUserAnswer = confirm("Do you

suppress confirmation dialog while using onbeforeunload

南笙酒味 提交于 2019-12-01 05:48:39
I am using onbeforeunload event to send ajax request to perform some clean up task. When I am using onbeforeunload, it shows the confirmation dialog on closing the tab. What I want is not to show any confirmation dialog and just send the clean up request. Following is the script I am using. window.onbeforeunload = unloadFunction; function unloadFunction() { var test_id = $('#test_id').val(); jQuery.ajax({ url: "/test/cleanup/" + test_id, cache: false }).done(function () { return false; }); return false; } Is there any way I can suppress the confirmation dialog? As per some suggestions, I have

Dismiss “Confirm Navigation” popup with Watir

允我心安 提交于 2019-12-01 04:16:29
I am trying to dismiss "Confirm Navigation" popup. This is how it looks like in Chrome. To see the popup: require "watir-webdriver" browser = Watir::Browser.new browser.goto "http://www.gravityforms.com/demo/wp-admin/admin.php?page=gf_new_form" browser.text_field(:id => "user_login").set "demo" browser.text_field(:id => "user_pass").set "demo" browser.button(:id => "wp-submit").click browser.refresh At the moment I override onbeforeunload when I visit the page, as suggested at http://watirwebdriver.com/javascript-dialogs/ browser.execute_script("window.onbeforeunload = function() {};") So, the

Is it possible to capture the user's answer when using onbeforeunload confirmation?

懵懂的女人 提交于 2019-12-01 03:56:49
问题 I need to warn users that they will lose information when leaving a page. This is easily done using the onbeforeunload event. My problem is that I want to take some action if the user decides to leave. Here's an example (I'm using jquery because it's loaded anyway): $(window).on('beforeunload', function(e){ return "Do you really want to leave?"; }); What I would like to do is something like this (this code doesn't work, I know, it's just an example to illustrate what I'm trying to do): $

window.onbeforeunload may fire multiple times

…衆ロ難τιáo~ 提交于 2019-12-01 03:52:07
Just because you don't see use for a feature doesn't mean it isn't useful. The Stack Exchange network, GMail, Grooveshark, Yahoo! Mail, and Hotmail use the onbeforeunload prompt to prevent/warn users that they are leaving a page after they have begun editing something. Oh yah, nearly every single desktop program that accepts saveable user-input data utilizes this prompt-user-before-leaving UX pattern. I have a function which behaves similarly to this one: window.onbeforeunload = function(){ // only prompt if the flag has been set... if(promptBeforeLeaving === true){ return "Are you sure you

Use JQuery or onbeforeunload for IE and FF

混江龙づ霸主 提交于 2019-12-01 03:14:10
I'm working in a Flex4 application, using javascript, in the "index.template.html" document. I'm having an issue being able to use onbeforeunload with Firefox. The application works perfectly in IE, but the exact same one doesn't sit well with FF. (See below) <script type="text/javascript"> window.onbeforeunload=before; window.onunload=after; function before(evt) { var flex=document.$(application)||window.$(application); flex.unloadMethod(); //custom method to log out the user } function after(evt) { } </script> From what I've found, FF doesn't seem to register onbeforeunload events, so I