JavaScript history.back() conditionally
My website uses asual address plugin for implementing hash based URL.
On one of the pages I have placed a开发者_如何转开发 back link. I want the following behavior on click of 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 are different before and after click of the link).
But this is not working in chrome. I also tried using history.length but no success.If you are going to the page by a link, you can check document.referrer and call history(-1) if it exists, but it will return empty if the user typed in the address, even if there is history. I don't think you can just get the url (or even existence) of unrelated browser history, as that would be a security problem.
<a href="#" onclick="javascript:window.history.back(-1);return false;">Back</a>
webkit / Chrome history.back(-1) onclick vs href
精彩评论