$(function() {
pushHistory();
window.addEventListener('popstate', function(e) {
alert('on popstate');
//自定义操作
window.location.href = '/xxx/xxx.html';
}, false);
})
function pushHistory() {
var state = {
title: "title",
url: "#"
};
window.history.pushState(state, "title", "#");
}
For security reasons, javascript does not allow to modify the existing url links in the history, but you can use the pushState method to add url links to the history, and provide popstate event monitoring to pop the url from the history stack. Since there is a popstate event provided
The method comes from: http://blog.csdn.net/mr_smile2014/article/details/52064650