If Browser is Internet Explorer: run an alternative script instead

后端 未结 10 582
后悔当初
后悔当初 2020-11-29 05:11

I\'m using an image carousel script that is quite heavy on the browser. It works great in Opera and Chrome, half decent in FF and absolutely breaks my balls in IE. So i\'d l

相关标签:
10条回答
  • 2020-11-29 05:35

    var browserName=navigator.appName; if (browserName=="Microsoft Internet Explorer") { document.write("Your html for IE") }

    0 讨论(0)
  • 2020-11-29 05:35

    Try this: The systemLanguage and the userLanguage is undefined in all browser.

    if(navigator.userLanguage !== "undefined" && navigator.systemLanguage !== "undefined" && navigator.userAgent.match(/trident/i)) {
        alert("hello explorer i catch U :D")
      }
    
    0 讨论(0)
  • 2020-11-29 05:37

    You define a boolean value with default of true, and then inside an IE conditional comment, set the value to false, and use the value of this to determine whether your advanced code should run. Something like:

    <script type="text/javascript">var runFancy = true;</script>
    <!--[if IE]>
    <script type="text/javascript">
        runFancy = false;
        //any other IE specific stuff here
    </script>
    <![endif]-->
    <script type="text/javascript">
        if (runFancy) {
             //do your code that works with sane browsers
        }
    </script>
    
    0 讨论(0)
  • 2020-11-29 05:42

    For IE10+ standard conditions don't work cause of engine change or some another reasons, cause, you know, it's MSIE. But for IE10+ you need to run something like this in your scripts:

    if (navigator.userAgent.match(/Trident\/7\./)) {
      // do stuff for IE.
    }
    
    0 讨论(0)
  • 2020-11-29 05:45

    You can do something like this to include IE-specific javascript:

    <!--[IF IE]>
        <script type="text/javascript">
            // IE stuff
        </script>
    <![endif]-->
    
    0 讨论(0)
  • 2020-11-29 05:49

    this code works well on my site because it detects whether its ie or not and activates the javascript if it is its below you can check it out live on ie or other browser Just a demo of the if ie javascript in action

    <script type="text/javascript">
    <!--[if IE]>
    window.location.href = "http://yoursite.com/";
    <![endif]-->
    </script>
    
    0 讨论(0)
提交回复
热议问题