首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过控制台识别PushState地址更新?

如何通过控制台识别PushState地址更新?
EN

Stack Overflow用户
提问于 2014-08-27 23:58:51
回答 1查看 240关注 0票数 0

您能告诉我是否有一种方法可以使用console/inspect-element/dev-tools来确定URL是否通过PushState更新?

例如,如果我去http://html5.gingerhost.com/,在“西雅图”,“伦敦”和“纽约”之间点击,那么我知道它正在通过PushState更新,但我如何才能通过控制台‘知道’?

一个正在开发的网站正在使用PushState和ReplaceState的混合,我渴望能够在开发工具控制台中看到它们。

EN

回答 1

Stack Overflow用户

发布于 2014-08-28 00:40:33

这仅用于调试目的,但您可以用自己的API覆盖默认API。

一种调试历史事件的快速而老套的方法:

代码语言:javascript
运行
复制
(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']);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25531838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档