Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to disable the browser back button while cliking the submit button in html page to secure the process has not terminated.

Here is the code to disable the back button in browser, but it's working in onload event only. when i am trying to use this in onclick event it wont work.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>New event</title>
</head>
<SCRIPT type="text/javascript">
window.history.forward();
function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">
<a href='page2.html' >Page 2</a>
</body>
</html>

Can anyone know how to disable the browser back button while i am clicking submit button in html page

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

It won't work because on click, it will run before navigation--so it will go to the nonexistant "forward" page.

Use onbeforeunload

var submitFlag=false;
//set submitFlag to true on onclick of submit button
window.onbeforeunload=function(e){ 
 if(submitFlag){
  return false;
 }
 return "Are you sure you want to leave?"

 }

This cannot force the user though. You can never force the user not to go back. Otherwise, this can lead to big security issues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...