Chrome:限制历史状态更改以防止浏览器挂起。ReactJs和jQuery

Chrome:限制历史状态更改以防止浏览器挂起。ReactJs和jQuery,jquery,reactjs,google-chrome,Jquery,Reactjs,Google Chrome,我只是在页面达到特定高度时更改url。但是 它向我显示了错误 chrome:限制历史状态更改为 防止浏览器挂起。1200高度后。但它正在发挥作用 在firefox中很好,因此有人知道如何防止此警告 如果是,请告诉我 函数myFunction(){ var h=($((“html”).scrollTop()); 如果(h==0){ window.history.pushState(null,null,“/”); //控制台日志(“0oo”); } 否则,如果(h>=1&&h=600&&h=1200

我只是在页面达到特定高度时更改url。但是 它向我显示了错误 chrome:限制历史状态更改为 防止浏览器挂起。1200高度后。但它正在发挥作用 在firefox中很好,因此有人知道如何防止此警告 如果是,请告诉我

函数myFunction(){
var h=($((“html”).scrollTop());
如果(h==0){
window.history.pushState(null,null,“/”);
//控制台日志(“0oo”);
}

否则,如果(h>=1&&h=600&&h=1200&&h=1800&&h=2400&&h=3000&&h=3600&&h我也遇到了同样的问题,我通过检查当前路径名来解决它,看看在更改它之前是否需要更改。这大大减少了历史状态更改的数量,因此避免了此警告

将此想法应用到您的代码中,我会这样做:

if(h == 0){
    if (window.location.pathname !== "/") {
        window.history.pushState(null,null,'/');
    }
}
else if(h >= 1 && h <= 600){
    if (window.location.pathname !== "abc") {
        window.history.pushState(null,null,"abc");
    }
}
... etc
else if (h >= 3600 && h <= 4200) {
    if (window.location.pathname !== "stu") {
        window.history.pushState(null,null,"stu");
    }
}

if(h==0){
如果(window.location.pathname!==“/”){
window.history.pushState(null,null,“/”);
}
}
如果(h>=1&&h=3600&&h
if(h == 0){
    if (window.location.pathname !== "/") {
        window.history.pushState(null,null,'/');
    }
}
else if(h >= 1 && h <= 600){
    if (window.location.pathname !== "abc") {
        window.history.pushState(null,null,"abc");
    }
}
... etc
else if (h >= 3600 && h <= 4200) {
    if (window.location.pathname !== "stu") {
        window.history.pushState(null,null,"stu");
    }
}