0

I have a page where I have the following code, first HTML, second JS

<div class='container'>
<div id='bradnav' class='breadnav clearfix'><a href='#' class='breadnava'><i class="fa fa-backward" aria-hidden="true"></i> Вернуться</a></div>
</div>

$(".breadnava").click(function (){
    window.history.back();
});

The problem with this code is that I also have a link on the page that is expanding hidden divs, with click on it, and this link has a href attribute set to #.

So as soon as I visit the page the link is smth like https://localhost/ikeen/keens.php?topicid=1 and I can use return link well, however when I click the link to expand hidden div-elements the URL naturally becomes https://localhost/ikeen/keens.php?topicid=1# (with the # at the end).

In the latter case I have to click return link twice to return to the page I came from. I know it's a small issue, but is there a way to go back to previous URL in JS, without having to go through all the links pressed on the page itself?

Thank you.

Undry
  • 427
  • 2
  • 15
  • So there is no way to go back one change in URL – Undry Apr 25 '20 at 23:19
  • There are plenty of ways to go back more than one. The problem, as you have stated it, is that you won't necessarily know how many to go back, since you insist on using elements. Once you know how many to go back, you can use history.go() and give it an argument for how many. [like this answer](https://stackoverflow.com/questions/32398647/use-window-location-href-to-go-2-pages-back-and-reload) –  Apr 25 '20 at 23:49