Answer the question
In order to leave comments, you need to log in
Location.hash......?
In general, there is a link like:
http://site.ru#more:next
There is a thing that catches the hash change in the browser to jquery:
$(window).bind('hashchange', function() {<br>
alert(location.hash);<br>
});
<a href='#more:next'>ссылка</a>
<a href='#more:next'>Ссылка</a> <!-- не работает --><br>
<a href='#more:next/'>Ссылка</a> <!-- не подходит --><br>
<a href='#more:next '>Ссылка</a> <!-- не работает в опере --><br>
Answer the question
In order to leave comments, you need to log in
And that won't work?
$('a').click(function(){
$(window).trigger('hashchange');
});
If the hash to "#more:next" event occurs, immediately change the hash to a string representing the page address (for example, "#page/42"). Thus, the next time you click on the "#more:next" link, the hash change event will fire again.
setTimeout(hashCheck, 100);
var oldHash = null;
function hashCheck()
{
if( oldHash !== location.hash )
{
// хеш изменился
}
setTimeout(hashCheck, 100);
}
If you click a second time on the link with the current hash, the event will not work, because the hash does not change.
Maybe we should handle the onclick event and call hashchange() in it?
And who is stopping you from changing the "active" hash to something else by loading and / or triggering the hashchange event?
ideologically, browsers are right - hash is used for positioning within the page, and if we are already in place, then there is no point in twitching. but if hash is used cunningly asshole , then, accordingly, it is also necessary to provide it cunningly.
var _hash = {
param: {},
current: '',
set: function(data)
{
if(_hash.current == data)
{
log('lock change hash');
return;
}
window.location.href = '#' + data;
},
get: function()
{
var _href = window.location.href.split('#'); _hash.param = {};
if(_href[1])
{
var _tmp = _href[1].split('&');
for(i in _tmp)
{
_hash.param[_tmp[i].split('=')[0]] = _tmp[i].split('=')[1];
}
}
_hash.current = _href[1];
log('param changed: ', _hash.param);
}
};
$(document).rady(function(){
$('a:not(.nolink)').on('click', function (event)
{
event.preventDefault();
_hash.set(this.href.replace(/^.*#/, ''));
});
$(window).bind('hashchange', function()
{
_hash.get();
});
_hash.get();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question