Using `[removed].hash.includes` throws “Object doesn't support property or method 'includes'” in IE11

后端 未结 8 861
生来不讨喜
生来不讨喜 2021-01-30 11:58

I am checking the URL to see if it contains or includes a ? in it to control the hash pop state in the window. All other browsers aren’t having an issue, only IE.

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 12:43

    According to the MDN reference page, includes is not supported on Internet Explorer. The simplest alternative is to use indexOf, like this:

    if(window.location.hash.indexOf("?") >= 0) {
        ...
    }
    

提交回复
热议问题