Failed to execute 'pushState' on 'History' error when using window.history.pushState function

前端 未结 2 1619
时光说笑
时光说笑 2020-12-05 17:55

I\'m using window.history in JavascriptMVC application to enable back/forward/refresh functionality for each controller. Every time I load a new controller I\'m

相关标签:
2条回答
  • 2020-12-05 18:03

    https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

    "The state object can be anything that can be serialized. Because Firefox saves state objects to the user's disk so they can be restored after the user restarts the browser, we impose a size limit of 640k characters on the serialized representation of a state object. If you pass a state object whose serialized representation is larger than this to pushState(), the method will throw an exception. If you need more space than this, you're encouraged to use sessionStorage and/or localStorage."

    Looks like the simple answer is that possible the state you are passing in is serializing to larger than 640k. I just ran into this bug, and I am almost certain that is the cause.

    0 讨论(0)
  • 2020-12-05 18:13

    window.history.pushState string size limit of 640k characters.

    Better switch to localStorage or sessionStorage.

    Source: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

    0 讨论(0)
提交回复
热议问题