Created
July 13, 2017 15:49
-
-
Save t-okushima/003c0e3d6a98cf11e287c59dae09a6f3 to your computer and use it in GitHub Desktop.
History APIで履歴をいじる ref: http://qiita.com/t-okushima/items/9f01d8a033e16557e62e
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
window.history.back(); |
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
window.history.forward(); |
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
window.history.go(1) |
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
window.history.pushState({name : 't-okushima'}, null, '/name') |
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
window.history.replaceState({name : 'aaaa'}, null, '/name') |
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
window.addEventListener('popstate', function(event) { | |
// 任意の処理 | |
var state = event.state; | |
alert(state.name): | |
}); |
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
window.history.state |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>History API Sample</title> | |
</head> | |
<body> | |
<label for='name'>Name</label> | |
<input type='text' id='name' value='' /> | |
<input type='button' id='pushButton' value='pushState' /> | |
<hr /> | |
<input type='button' id='replaceButton' value='replaceState' /> | |
<script> | |
document.getElementById('pushButton').addEventListener('click', function() { | |
var name = document.getElementById('name').value; | |
window.history.pushState({name : name}, null, './history-api.html'); | |
}); | |
document.getElementById('replaceButton').addEventListener('click', function() { | |
var name = document.getElementById('name').value; | |
window.history.replaceState({name : name}, null, './history-api.html'); | |
}); | |
window.addEventListener('popstate', function(e) { | |
var state = e.state; | |
if (state) { | |
document.getElementById('name').value = state.name; | |
alert(state.name); | |
} else { | |
document.getElementById('name').value = ''; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment