0

I have those url's :

<ul class="tm-nav-links">
      <li class="tm-nav-item active">
              <a href="#" data-linkid="0" data-align="right" class="tm-nav-link">Intro</a>
      </li>
      <li class="tm-nav-item">
              <a href="#" data-linkid="1" data-align="right" class="tm-nav-link">About</a>
      </li>
      <li class="tm-nav-item">
              <a href="#" data-linkid="1" data-align="right" class="tm-nav-link">Contact-us</a>
      </li>   
</ul>

For exemple, when I select contact-us I want to keep the previous selected url in var, because I want to use it to go back when I click on the back button of the browser.

I tried

$('.tm-nav-item li.active:last')

But it doesnt work. Any idea? Thank you

emrhzc
  • 1,347
  • 11
  • 19

2 Answers2

0

Assuming that you are navigating within one page just by changing the scroll position and targetting sections of your page you should change the above strategy.

  1. You should give those anchors some hash links like: #intro, #about, #contact-us

  2. Then on hashChange scroll to those positions. Then on browser back you will be able to return to the previous positions.

In modern browsers (IE8+, FF3.6+, Chrome), you can just listen to the hashchange event on window.

In some old browsers, you need a timer that continually checks location.hash. There are jQuery plugins which will work well with older browsers also.

-1

Solved with

history.pushState()

and

history.replaceStat()