Can use pushState

前端 未结 2 1445
一个人的身影
一个人的身影 2020-12-15 09:59

Does anyone know of a library that determines if pushState can be used?

I was using this:

if(window.history.pushState){
    window.history.pushState(         


        
2条回答
  •  一个人的身影
    2020-12-15 10:29

    Looking at the Modernizer source code this is how it checks for push state:

      tests['history'] = function() {
          return !!(window.history && history.pushState);
      };
    

    So a simple way for you would just be:

    var hasPushstate = !!(window.history && history.pushState);
    

    One must first check for the existence of window.history before going two levels deep and that's probably why you were experiencing an error.

提交回复
热议问题