Anchor tags not working in chrome when using #

前端 未结 9 2211
一个人的身影
一个人的身影 2020-12-01 15:50

Here is the code I am using on my page,

  • Sound
  • (in a menu which appears on

    9条回答
    •  -上瘾入骨i
      2020-12-01 16:24

      Turns out this was a bug in certain versions of chrome, posting workaround for anyone who needs it! :)

      $(document).ready(function () {
              var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
              if (window.location.hash && isChrome) {
                  setTimeout(function () {
                      var hash = window.location.hash;
                      window.location.hash = "";
                      window.location.hash = hash;
                  }, 300);
              }
          });
      

    提交回复
    热议问题