Prevents the user from pressing the previous page button

Source: Internet
Author: User
There are often friends in the discussion area who ask this question, how can you prevent users from pressing back to the previous page, and why would you ask this question? It's usually a matter of preventing the user from repeating an application, for example, the new data library, if the user pressed back to the page, may cause duplicate new information, today this article will introduce how to "as possible" to prevent users from pressing back to the previous page

Servo-side Prevent cache

First, let's look at the server-side approach, where the ASP's Response object provides several web cache-related dependencies, which are described below

The nature of the said
CacheControl whether the proxy server is quick to fetch the output results of an ASP
Expires Web Cache Overdue Time
ExpiresAbsolute Specify the overdue time for the Web cache


So if you want to prevent the web from being quickly fetched, you can do this

<%
Response.Buffer = True
Response.ExpiresAbsolute = Now ()-1
Response.Expires = 0
Response.CacheControl = "No-cache"
%>

Using this method, the user can still go back to the previous page, but since the web is not being fetched, the browser must make HTTP requests to the server again, that is, this web will be collated (Refresh)

Using the client to prevent fast fetching

You can also use the client-side (client-side) approach,

<meta http-equiv= "Expires" content= "0" >
<meta http-equiv= "Cache-control" content= "No-cache" >
<meta http-equiv= "Pragma" content= "No-cache" >

And the method of the servo end is the same, but there are a few points to note

Pragma: Use Pragma when using a secure connection, and if used in an unsecured connection, the effect is the same as for Expires:-1, which is that the web is still being fetched, but will be immediately exceeded
Meta HTTP-EQUIV tags Cache-control are not suitable for Internet Explorer 4, version 5
To remove a tool column

This is a way of looking at the Internet, and it's kind of interesting, so here's how it's done, use the Window.Open method to open a new window, and then turn off the original window, but the point is to remove the tool column when you open the window.

<script language= "JavaScript" >
<!--
function Openwindow (URL) {
newpage = window.open (URL, ' newpage ', ' toolbar=no ');
Newpage.focus ();
Self.close ();
}
-->
</script>
<a href= "Javascript:openwindow (' nextpage.html ');" > next Page </a>

is also a method, but it should be very few people will use, a bit of trouble! Situation and press the right mouse button there is also the menu to go back to the previous page of the choice, this method cautious prevent the gentleman not to the villain!

Using Location.replace

The replace () method of the Javascript location object will overwrite the browser with the specified Web site. Currently browsing through history, that is, when you use this method, the browser forgets past browsing, and as you first opened the browser, the button on the previous page is grayed out and the

You can do this.

<a href= "Javascript:location.replace (' nextpage.html ')" > next page </a>

Looks like this is probably the best way at the moment! There are still some shortages, because not all situations can be applied, for example, when you use Response.Redirect, this method will not be used!

It is possible to come up with a conclusion that it is impossible to completely shut down the browser's ability to return to the previous page (the current browser), the only thing that can be done is to adapt the above methods to prevent users from pressing back to the previous page.

Hopefully this article will help you!



Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.