Javascript or Jquery to detect page refresh and redirect to error page - avoid duplicate data submission -


tried jquery redirect error page when jsp page refreshed using f5 or browser refresh button following :

function confirmexit() {    alert("exiting");    window.location.href='index.html';    return true; } window.onbeforeunload = confirmexit; 

the above code gives alert when page refreshed, window.onbeforeunload alerts when save button pressed , page not redirected , duplicate data submitted. im doing avoid duplicate data submission on refresh. please help.

you can't relocate onbeforeunload event. browser won't allow it, because of security reasons. (eg, keep on page forever.)

the thing can onbeforeupload ask user if he's sure if wants exit.

you need accept there little can in preventing user make http request, refreshing or whatever means. instead need solve on server side, redirecting browser if same request made twice.


to answer question save button (even though isn't relevant more).

var saved = false;  function confirmexit() {    if (saved) return;    return "are sure want leave?"; } window.onbeforeunload = confirmexit;  document.getelementbyid('#save').onclick = function() {    saved = true; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -