问题
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
回答1:
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;
}
});
});
回答2:
Please don't do this.
But you could use a cookie
psuedo code
if !cookie_exists()
disable_back_button()
create_cookie()
Then delete the cookie when the user leaves.
Referrer can be edited, so I don't recommend that
but I also don't recommend doing this at all, its annoying.
来源:https://stackoverflow.com/questions/5490466/javascript-jquery-back-button-so-long-as-last-page-was-part-of-current-site