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

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

    You could use conditional compiling in conjunction with conditional comments

    Here a short overview of how this could work.

    1. Always show the bar
    2. Set a flag in javascript. IEMinor=false
    3. Set the flag to true if IE <= 9, by using a script tag and conditional comments
    4. Use conditional compiling to hide the bar if @_jscript_version > 9 (actually not needed) and IEMinor===false

    Not Supported

    I was too lazy to add the script type...

    Here is an example on JSBin which doesn't show the bar in IE 10+ (untested). And shows it in other cases.

    Note: I didn't make it look exactly like in the screenshot, you should get that part working

    Edit: Using the browsermode of IE to test against IE<10 seems to work
    Edit2: Whoops i thought from the picture IE9 is unsupported too, to allow IE9 change lte IE 9 to lt IE 9 and @_jscript_version > 9 to >= 9

提交回复
热议问题