仅嗅探 IE8

发布于 2024-12-18 08:30:28 字数 131 浏览 7 评论 0原文

如果浏览器是 IE8,那么嗅探的最短 JavaScript 代码是什么?

我想为 IE8 做一些特别的事情,

我不想连接一个可以返回所有浏览器和版本的库。 我只想写一两行来判断是否是IE8。

谢谢 佐

What's the shortest javascript code to sniff if the browser is IE8.

I want to do something special just for IE8

I don't want to wire up a library that gives me back all the browsers and the versions.
I just want to write one or two lines to work out if it's IE8.

thanks
zo

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

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

发布评论

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

评论(3

堇年纸鸢 2024-12-25 08:30:28

我发现的最好方法是使用条件样式或条件编译:

var isIE8 = false;
<!--[if IE 8]>
        <script type='text/javascript'>
            isIE8 = true;
        </script>
<![endif]-->

然后在代码中,您可以简单地检查此值:

<script type='text/javascript'>
   if (isIE8) {
       alert('Your browser is IE8');
   }
</script>

The best way I found is to use conditional styles, or conditional compiling:

var isIE8 = false;
<!--[if IE 8]>
        <script type='text/javascript'>
            isIE8 = true;
        </script>
<![endif]-->

Then in your code, you can simply check this value:

<script type='text/javascript'>
   if (isIE8) {
       alert('Your browser is IE8');
   }
</script>
夏天碎花小短裙 2024-12-25 08:30:28

您可以使用以下方法在 HTML 中执行此操作:

<!--[if IE 8]>
<script type="text/javascript" src="IE8.js">
<![endif]-->

另请参阅本教程:http://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx

You can do this in HTML, by using this:

<!--[if IE 8]>
<script type="text/javascript" src="IE8.js">
<![endif]-->

Also take a look at this tutorial: http://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx

不再让梦枯萎 2024-12-25 08:30:28

在 HTML 中,您可以使用条件注释包含某些 IE 浏览器的标记:

<!--[if IE 8]>
<script type="text/javascript" src="ie8_hacks.js">
<![endif]-->

In your HTML, you can include markup for certain IE browsers using conditional comments:

<!--[if IE 8]>
<script type="text/javascript" src="ie8_hacks.js">
<![endif]-->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文