广告:Fundebug错误监控插件,及时发现Bug,提高Debug效率!页面//初始化页面监听document.addEventListener(“DOMContentLoaded”, ready);// 页面跳转hashdocument.addEventListener(“hashchange”, navigation);// 监听pop和push需要自定义document.addEventListener(“popstate”, navigation);document.addEventListener(“pushState”, navigation);//离开页面监听document.addEventListener(“beforeunload”, leave);自定义监听popstate和pushStatehistory.pushState = this.resetHistory(“pushState”);history.replaceState = this.resetHistory(“replaceState”); resetHistory(type) { let orig = history[type]; return function() { let rv = orig.apply(this, arguments); let e = new Event(type); e.arguments = arguments; window.dispatchEvent(e); return rv; }; }errorwindow.onerror = function (errorMsg, url, lineNumber) { alert(errorMsg + lineNumber);//错误信息+lineNumber }; window.addEventListener(‘unhandledrejection’, event => { console.log(‘unhandledrejection:’ + event);//打印event查看所有报错信息 });