如果浏览器是 Internet Explorer:运行替代脚本

发布于 2024-10-07 05:06:54 字数 310 浏览 4 评论 0原文

我正在使用一个图像轮播脚本,该脚本对浏览器的负载相当大。它在 Opera 和 Chrome 中运行得很好,在 FF 中还算不错,在 IE 中绝对让我大吃一惊。所以我想为 IE 用户提供一种无需任何操作/JS 的简单 HTML 的替代方案。

该脚本不使用 MT 或 jQuery,并且有 380 行 JS。是否可以为 IE 用户提供纯 HTML 替代方案?

var browserName=navigator.appName; if (浏览器名称==“Microsoft Internet Explorer”) { // 我可以使用什么命令? }

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 like to give IE users an alternative of simple HTML without any action/JS.

The script doesn't use MT or jQuery and its like 380 lines of JS. Would it be possible to give IE users a plain HTML alternative?

var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
// what command can i use?
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

故事未完 2024-10-14 05:06:54

这篇文章非常有解释性: http://msdn.microsoft.com/ en-us/library/ms537509%28v=vs.85%29.aspx

如果你的 JS 不引人注目,你可以使用:

<![if !IE]>
   <script src...
<![endif]>

This article is quite explanatory: http://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx.

If your JS is unobtrusive, you can just use:

<![if !IE]>
   <script src...
<![endif]>
最笨的告白 2024-10-14 05:06:54

您可以执行以下操作来包含特定于 IE 的 javascript:

<!--[IF IE]>
    <script type="text/javascript">
        // IE stuff
    </script>
<![endif]-->

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

<!--[IF IE]>
    <script type="text/javascript">
        // IE stuff
    </script>
<![endif]-->
为人所爱 2024-10-14 05:06:54

对于 IE10+ 标准条件,由于引擎更改或其他原因而无法工作,原因是 MSIE。但对于 IE10+,您需要在脚本中运行类似以下内容:

if (navigator.userAgent.match(/Trident\/7\./)) {
  // do stuff for IE.
}

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.
}
没︽人懂的悲伤 2024-10-14 05:06:54

您定义一个默认值为 true 的布尔值,然后在 IE 条件注释 中,设置将值设置为 false,并使用该值来确定是否应运行您的高级代码。像这样的东西:

<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>

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>
梦萦几度 2024-10-14 05:06:54

var browserName=navigator.appName; if (浏览器名称=="Microsoft Internet Explorer") {
document.write("您的 IE html")
}

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

胡渣熟男 2024-10-14 05:06:54

这是我使用的脚本,它的作用就像一个魅力。我使用了 Ender 建议的布尔方法,因为其他方法仅使用 IE 特定脚本向 IE 添加了一些内容,但没有删除原始代码。

    <script>runFancy = true;</script>
<!--[if IE]>
<script type="text/javascript">
    runFancy = false;
 </script> // <div>The HTML version for IE went here</div>
<![endif]-->

    // Below is the script used for all other browsers:
    <script src="accmenu/acac1.js" charset="utf-8" type="text/javascript"></script><script>ac1init_doc('',0)</script> 

Here is the script i used and it works like a charm. I used the boolean method Ender suggested as the other ones using only the IE specific script adds something to IE but doesn´t take the original code out.

    <script>runFancy = true;</script>
<!--[if IE]>
<script type="text/javascript">
    runFancy = false;
 </script> // <div>The HTML version for IE went here</div>
<![endif]-->

    // Below is the script used for all other browsers:
    <script src="accmenu/acac1.js" charset="utf-8" type="text/javascript"></script><script>ac1init_doc('',0)</script> 
一梦浮鱼 2024-10-14 05:06:54

试试这个:
systemLanguage 和 userLanguage 在所有浏览器中都是未定义的。

if(navigator.userLanguage !== "undefined" && navigator.systemLanguage !== "undefined" && navigator.userAgent.match(/trident/i)) {
    alert("hello explorer i catch U :D")
  }

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")
  }
疯狂的代价 2024-10-14 05:06:54

请注意,您还可以在纯js中确定脚本在哪个浏览器中通过以下方式执行:window.navigator.userAgent

但是,这不是推荐的方式,因为它可以在浏览器设置中进行配置。更多信息请访问:https://developer.mozilla.org/fr/文档/DOM/window.navigator.userAgent

Note that you can also determine in pure js in what browser you script is beeing executed through : window.navigator.userAgent

However, that's not a recommended way as it's configurable in the browser settings. More info available there: https://developer.mozilla.org/fr/docs/DOM/window.navigator.userAgent

往日情怀 2024-10-14 05:06:54

请参阅 Microsoft 开发人员档案中的此脚本: https:// /msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx

我已经在很多项目中使用过这个脚本,从来没有遇到过任何问题。

See this script in Microsoft's developer archives: https://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx

I have used this script in quite a few projects, never had any problems.

零度℉ 2024-10-14 05:06:54

这段代码在我的网站上运行良好,因为它会检测是否是 ie 并激活 javascript(如果在下面)您可以在 ie 或其他浏览器上实时查看它 只是 if ie javascript 实际操作的演示<​​/a>

<script type="text/javascript">
<!--[if IE]>
window.location.href = "http://yoursite.com/";
<![endif]-->
</script>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文