Skip to content

Instantly share code, notes, and snippets.

@amachang
Created February 20, 2012 10:06
Show Gist options
  • Save amachang/1868654 to your computer and use it in GitHub Desktop.
Save amachang/1868654 to your computer and use it in GitHub Desktop.
jQuery hashchange test
var host = location.host;
var protocol = location.protocol;
$(function() {
$(window).hashchange(function() {
// ここらへんで、現在の状態を location.hash から引けるように保存する。
// 次に、 location.hash から依然に保存されたものがあれば、取得する(リフレッシュするかも)
$('title').text(location.hash);
$('#log').text($('#log').text() + 'push ' + location.hash + "\n");
});
$(document).click(function(e) {
var href = $(e.target).get(0).href;
if (href.indexOf(protocol + '//' + host + '/') === 0) {
location.hash = "!" + href.replace(protocol + '//' + host, '');
e.preventDefault();
}
});
});
var test = function() {
location.hash = '!test';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment