I'm using Twitter Bootstrap 3.0, using the ScrollSpy plugin to activate my "nav" links as I scroll down. Now I want to automatically update the URL in the address bar (using window.history.pushstate) in response to the ScrollSpy event "activate.bs.scrollspy".
How can I identify the "nav" element that ScrollSpy has activated for me?
My code looks something like this.
<body data-spy="scroll" data-target="#primarynavbar">
<div id="primarynavbar" class="navbar navbar-inverse navbar-fixed-top" role="navigation">
...
...
<li><a href="#contact">Contact Us</a></li>
...
...
<div id="contact" />
...
...
<script>
$('#primarynavbar').on('activate.bs.scrollspy', function () {
window.history.pushstate('http://abcd.com#contact')
});
</script>
...