How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

前端 未结 25 3283
谎友^
谎友^ 2020-11-22 06:19

How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

I tried this, but

25条回答
  •  猫巷女王i
    2020-11-22 06:42

    If you want to target IE 10 with Vanilla JavaScript, you might want to try CSS property detection:

    if (document.body.style.msTouchAction != undefined) {
      document.body.className = 'ie10';
    }
    

    CSS properties

    Instead of msTouchAction you can also use one of these CSS properties, because they are currently only available in IE 10. But this might change in the future.

    • msTouchAction
    • msWrapFlow
    • msWrapMargin
    • msWrapThrough
    • msScrollLimit
    • msScrollLimitXMin
    • msScrollLimitYMin
    • msScrollLimitXMax
    • msScrollLimitYMax
    • msFlexbox
    • msFlex
    • msFlexOrder

    Test page

    I've put together a test page with all properties on CodePen.

提交回复
热议问题