A
A
Alexey Yankiv2013-12-26 16:01:21
JavaScript
Alexey Yankiv, 2013-12-26 16:01:21

How to track location.hash changes?

Good afternoon.
There has been such a problem:
1. There is the following html code:
A wrapper for displaying a modal window:

<div class="modal" id="auto1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

 <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="myModalLabel">{modalLabel}</h3>
</div>
<div class="modal-body">
<p>
{modalContent}
</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Закрыть</button>
</div>
</div>

And link:
<a id="bhmenu1" class="bhmenu" href="#auto1" data-toggle="modal">
    Автоматизация документооборота
</a>

In this case, when clicking on the link, the hash is passed to the modal window output wrapper class as id
. The problem is that there can be several links, that is:
href="auto1"
href="auto2"

Etc.
I don’t want to produce entities and make my own wrapper for each link - this is wrong.
Attention question: How can I catch a change in the hash parameter that is passed by reference and change the id
Googling, I did not find a sensible solution for tracking document.location.hash changes, please kick in the right direction.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Melnikov, 2013-12-26
@mlnkv

window.addEventListener('hashchange', hashchange);

function hashchange(){ 
  var hash = location.hash;
  /* do something */
}

A
Alexey Yankiv, 2013-12-26
@netaspid

stupid. maybe with an example?

F
frees2, 2013-12-26
@frees2

without a hash seems to plow for a long time

$videoIdprint='<span onclick="ytplayer.loadVideoById(\''.$videoId.'\', 0);history.pushState(null, null, \''.$videoId.'\');return false">..........

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question