How to enable / disable the click to go forward button in a browser using js history?

Using history.pushState , we can change the current url using the history API. Using the popstate function, we can return to the previous page. But, going back, I found that the direct link button in the browser "Click here to go forward" is disabled. Now, using the story, I need to access this button property.

How can we access the URL of a direct page using the story API?

+7
javascript jquery html5 browser-history html5-history
source share
2 answers

Do you manually enter the state? It looks like he is being removed.

To return, you must use history.back() . history.back() save the record in history so you see that the forward button is on to go back.

You can also specify how many records will be returned using history.go(X) . ex: history.go(-3) will return you three pages.

Source: MDN

+1
source share

I prefer the AJAX method when backward (or forward) occurred all js variables (page area) have old values. firstly, you get a JS variable with time (Server), then check this value with AJAX. when Hacker (Super-Beginner) wants to access the url via back / forward, this method shows alert('You are Hacker.Oops') and changes location.

page.php

 <script type="text/javascript"> <?php $expire=time()+120; // 2 minute $expire_hash=md5($expire+'SECRET-KEY'); // optional for security purposes ?> $.get('anti-back-forward.php?<?php echo "expire=$expire&expire_hash=$expire_hash"?>', function(content){ if(content=='BAD'){ alert('You are hacker.Oops'); window.location='index.php'; } }); </script> 

anti-back-forward.php

 extract($_GET); if(($expire<time()) || $expire_hash!=md5($expire+'SECRET-KEY')) die('BAD'); echo "OK"; 
0
source share

All Articles