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

前端 未结 25 2620
谎友^
谎友^ 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条回答
  • 2020-11-22 06:55

    With JavaScript:

    if (/Trident/g.test(navigator.userAgent)) { // detect trident engine so IE
            document.getElementsByTagName('html')[0].className= 'no-js ie'; }
    

    Work for all IE.

    IE08 => 'Trident/4.0'
    
    IE09 => 'Trident/5.0'
    
    IE10 => 'Trident/6.0'
    
    IE11 => 'Trident/7.0'
    

    So change /Trident/g by /Trident/x.0/g where x = 4, 5, 6 or 7 (or maybe 8 for the future).

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