JavaScript history.back () conditionally

My site uses the address plugin to implement the hash url.
On one of the pages I posted the link back . I want the following behavior when clicking this link.

$ ('# back_link'). click (function () {
 If there is any entry in history it should do history.back ()
 If no entry in history, load a default page.
})

Is it possible?

Note. I can do this in Firefox (window.location.hash is different before and after clicking on the link).
 But this does not work in chrome. I also tried using history.length but did not succeed.

+3
source share
2 answers

, document.referrer (-1), , , , . , URL ( ) , .

0
<a href="#" onclick="javascript:window.history.back(-1);return false;">Back</a>

webkit/Chrome history.back(-1) onclick vs href

0

Source: https://habr.com/ru/post/1764159/


All Articles