Javascript / jQuery back button - if the last page was part of the current site?

In the code below, I can make the back button, but is there a way to make the link necessary so that the last page is part of the current site?

$(document).ready(function(){ $('a.back').click(function(){ parent.history.back(); return false; }); }); 

If the last page was not part of the current site, then the ideal id would like to specify a backup link.

thanks

+6
javascript jquery back
source share
2 answers

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; } }); }); 
+8
source share

Please, do not do that.

But you can 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 do not recommend that

but I also do not recommend doing this at all, it annoys him.

0
source share

All Articles