您能告诉我是否有一种方法可以使用console/inspect-element/dev-tools来确定URL是否通过PushState更新?
例如,如果我去http://html5.gingerhost.com/,在“西雅图”,“伦敦”和“纽约”之间点击,那么我知道它正在通过PushState更新,但我如何才能通过控制台‘知道’?
一个正在开发的网站正在使用PushState和ReplaceState的混合,我渴望能够在开发工具控制台中看到它们。
发布于 2014-08-28 00:40:33
这仅用于调试目的,但您可以用自己的API覆盖默认API。
一种调试历史事件的快速而老套的方法:
(function(window, listenTo) {
var history = window.history;
// replaces default APIs with function that also logs the arguments
listenTo.forEach(function(key) {
var original = history[key];
history[key] = function() {
console.log('history.' + key, arguments);
original.apply(history, arguments);
};
});
// add a listener to the popstate event for debugging purposes
window.addEventListener('popstate', function() {
console.log('onpopstate', arguments);
});
})(window, ['pushState', 'replaceState']);
https://stackoverflow.com/questions/25531838
复制相似问题