The search on the Internet is ASP php how to prevent the back button cache it?
Reply content:
The search on the Internet is ASP php how to prevent the back button cache it?
Unable to block browsing history.back()
behavior
You can consider setting the page as no cache
$nocache = array( 'Expires' => '0', 'Cache-Control' => 'no-store,private, post-check=0, pre-check=0, max-age=0', 'Pragma' => 'no-cache');foreach($nocache as k => $v) header($k.': '.$v);
If you really want to reject the back, you can use the following method to simulate, consider a jump, so back again , will automatically jump to the current page, similar to the refresh
header('Location: index.php');
Take the homepage page link to say:
3
Search engine crawler will be based on the href access to the /index.php?page=3
3rd page of data, conducive to SEO.
Users in the browser right-click "Open in New tab" also can access to/index.php?page=3.
If the user clicks the link directly on the page, the Click event is triggered, the local data is loaded and rendered by JS via Ajax, and the Location.hash is set to /index.php#/page/3
.
location.hash = "#/page/3";
The browser can remember Location.hash history, we only need to listen to Location.hash changed events hashchange
(support IE8, not support IE7/6) can realize the user click the Browser Back button when the page reload.
$(window).on("hashchange", function(){ alert(location.hash); //输出#/page/2 var arr = location.hash.split("/"); // ["#", "page", "2"] if(arr[1] == "page") { page(arr[2]); //AJAX局部加载第2页数据 //location.href = "/index.php?page="+arr[2]+"&"+new Date().getTime(); //直接访问第2页 }});
Above this "SEO and experience of the hyperlink design" should be able to meet the landlord needs, but the need for a certain cost of transformation.
Page loading complete JS Refresh page location.href = Location.href