With the code below I can make a 'back' button, but is there a way of making the link require that the last page was part of the current site?
$(document).ready(function(){
$('a.back').click(function(){
parent.history.back();
return false;
});
});
If the last page wasn't part of the current site then ideally id like to be able to specify a backup link.
Thanks
You can simply fire the “popState” event in JQuery e.g: $(window). on('popstate', function(event) { alert("pop"); });
Master, I have used the code that to prevent the user from going back to previous pages after logout. function preventBack() { window. history. forward(); } setTimeout("preventBack()", 0); window.
location. replace() it is used to clear the last entry in the history and replace it with the address of a new url. replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.
How about using document.referrer
?
$(document).ready(function(){
$('a.back').click(function(){
if(document.referrer.indexOf(window.location.hostname) != -1){
parent.history.back();
return false;
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With