onhashchange with IE 9

前端 未结 3 764
春和景丽
春和景丽 2021-01-14 06:30

I have the following code

$(document).ready(function() {
   if (\"onhashchange\" in window) {
      alert(\"The browser supports the hashchange event!\");
           


        
3条回答
  •  旧巷少年郎
    2021-01-14 07:13

    See this: link

    Does the browser support window.onhashchange?

    Note that IE8 running in IE7 compatibility mode reports true for 'onhashchange' in window, even though the event isn't supported, so also test document.documentMode.

    var docmode = document.documentMode;
    if ('onhashchange' in window && (docmode === undefined || docmode > 7 )) {
        window.onhashchange = checkHash;
    }
    

提交回复
热议问题