JavaScript to prevent form recurrence, anti-refresh, anti-rewind _ form effects
Source: Internet
Author: User
1 server-side workaround. This is the most recommended method for me. The advantage is accurate judgment, the most compatible.
Procedure: A page displays the form, then submits the B page processing, after processing, redirects to the C page displays the result.
1.0 generate a flag ID in the session when accessing page A, for example
Pseudo code
Session ("Submitid") =random ()
and write this value to a hidden input in the form.
Pseudo code
<%response.write ("<input name=submitid2 type=hidden value=\" "+session (" Submitid ") +" > ")%>
1.1 b page processing to determine whether the form submitted by the SUBMITID2 value and session of the Submitid consistent, inconsistent words redirect to the error page, the same words in the session of the Submitid empty and then take the form processing
Pseudo code
Session ("Submitid") = ""
Then process the submission ...
Redirect to C page after processing completes
1.2 C page In fact, there is nothing to say, is a display processing results of the page.
2 Client with JS solution
This method is not good, because it will inevitably encounter different browser compatibility issues, and is bound to be bypassed. The only advantage is that it's simple and doesn't require too much coding.
2.0 Prevent back
Add this code at the top of each page
<script>window.history.forward ();</script>
2.1 Prevent refreshing
I can't think of any good way to do it. Because there are too many places to block. Had to adopt a very bad way:
<body onunload= "location= ' About:blank ' >" <!--This method is only an idea, without debugging-->
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service