Show a message if the browser is not internet explorer 9 or greater

后端 未结 10 1172
北恋
北恋 2020-12-31 01:18

I would like to show my users a bar that looks like this, if:

  1. Browser is not IE; or
  2. Browser is IE but is version 8 or earlier

相关标签:
10条回答
  • 2020-12-31 01:48

    Checking if browser engine is Trident 6+ (IE 9, 10, 11) should do (demo):

    (function () {
      var trident = {
        string: navigator.userAgent.match(/Trident\/(\d+)/)
      };
    
      trident.version = trident.string ? parseInt(trident.string[1], 10) : null;
    
      if (!trident.string || trident.version < 6) {
        document.body.innerHTML = '<div class="alert">Not supported.</div>' +
          document.body.innerHTML;
      }
    })();
    

    However, the sniffing may break in IE 11 final or future versions if Microsoft will decide to change userAgent string.

    0 讨论(0)
  • 2020-12-31 01:48

    try $.browser.version
    check here http://api.jquery.com/jQuery.browser/

    0 讨论(0)
  • 2020-12-31 01:49

    Actually in SharePoint (OP mentioned that) there is a built-in variable browseris. It's available in the global window scope. Answering OP question:

    1. Browser is not IE;
    • use browseris.ie
    1. Browser is IE but is version 8 or earlier
    • use browseris.ie8down

    (tested in SP2013 on-prem)

    0 讨论(0)
  • 2020-12-31 01:52

    I like the simple conditional html. (Simpler always seems better.)

    Another more comprehensive javascript alert can be found at: http://www.browser-update.org

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