Created
February 20, 2012 10:06
-
-
Save amachang/1868654 to your computer and use it in GitHub Desktop.
jQuery hashchange test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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