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

后端 未结 10 1315
北恋
北恋 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:37

    HTML

    IE 9 and earlier (down to, I think, IE 4) can be identified using conditional comments in HTML.

    As @Jost noted, you could use them to warn IE users on IE 8 and earlier, like this:

    
    

    However, as IE 10 dropped support for these, you can't use them to identify non-IE browsers.

    jQuery

    jQuery used to include a browser detection module ($.browser), but it was removed in jQuery 1.9. If you can use an earlier version of jQuery (e.g. 1.8.3) or the jQuery Migrate plugin, then you could use this to show the banner.

    if ( !$.browser.msie || $.browser.version < 9 ) {
        // Add banner to the page here.
    }
    

    Browser Detection in general

    Please note that browser detection is difficult. New browsers are coming out all the time, so any browser support plugin can rapidly become out of date, as can the premise on which you base your warning messages. jQuery's browser detect was the most consistently maintained, and even they gave up on it in the end.

    These days, web developers are generally expected to write code that works cross-browser, and use feature-detection to deal with browsers that don't support the features they want to use.

    As you're working on a SharePoint site, presumably it's for internal company use, and the company is Microsoft-centric. It sounds like you're developing the site to work in IE, and ignoring other browsers during development.

    If you can reasonably expect most of your users to be on some version of IE, maybe the conditional comment warning is enough.

提交回复
热议问题