javascript - How to prevent page refresh before a user has selected a button on a dialog box? -


my web app listening out page refresh.

i attempting doing following:

window.onbeforeunload = dialogbox; 

the idea display dialog box in order prevent page refreshing until user has made choice selecting either of 2 buttons determines whether continue refresh or cancel refresh.

unfortunately page displays dialog box brief second , continues refresh. there anyway can use 'onbeforeunload' prevent page continuing refresh , show dialog box?

is impossible achieve using 'onbeforeunload'?

the code dialog box:

function dialogbox() {     $("#dialog").html("");     $("#dialog").append("there appears unsaved changes");     $( function() {         $( "#dialog" ).dialog({             modal: true,             buttons: {                 cancel: function() {                     $(this).dialog( "close" );                  },                  "save": function() {                  },             },         })     }); } 

thank time.

edit: don't want prevent user refreshing. rather display generic pop-up box appears when using onbeforeunload, want display custom dialog box calling function generates that. able display split second, , not permanently until has made selection. selection should either continue refresh or half entirely selecting 'cancel'.

if helps, using google chrome web browser of choice.

try use history.go(-1); before calling function


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -