为什么'string'[0]在ie8 + IIS7.5上的行为与其他浏览器或本地文件不同? [英] Why does 'string'[0] behave differently on ie8 + IIS7.5 than other browsers or local file?

查看:159
本文介绍了为什么'string'[0]在ie8 + IIS7.5上的行为与其他浏览器或本地文件不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下Html文件:

Consider the following Html file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>test</title>
        <style type="text/css">

        </style>
    </head>
    <body>
        <script type="text/javascript">
            alert('' +
                '\'test\'[0] = \'' + 'test'[0] + '\'\n' +
                '\'test\'.charAt(0) = \'' + 'test'.charAt(0) + '\'\n'
            );
        </script>
    </body>
</html>

当我在本地计算机上打开此文件时,它会提供以下输出(在ie8和Chrome中) :

When I open this file on my local machine it gives the following output (both in ie8 and Chrome):

'test'[0] = 't'
'test'.charAt(0) = 't'

当我在IIS7.5上托管这个文件时,我仍然在Chrome中得到相同的结果但ie8给出了结果如下:

When I host this file on IIS7.5 I still get the same result in Chrome but ie8 gives the following result:

'test'[0] = 'undefined'
'test'.charAt(0) = 't'

这怎么可能?

推荐答案

好的,我发现它是由于兼容性视图。 Internet Explorer是标准配置(我认为,我不是这台笔记本电脑的拥有者),可选择在兼容性视图中显示所有Intranet页面。为了强制它使用ie8兼容性视图,我必须在head元素中添加以下元标记:

OK I found out it was due to compatibility view. Internet explorer comes standard (I think, I am not the owner of this laptop) with the option to display all intranet pages in compatibility View. To force it to use ie8 compatibility view I had to add the following meta tag to the head element:

<meta http-equiv="X-UA-Compatible" content="IE=edge" > <!-- IE8 mode -->

您也可以在页面>兼容性视图设置下关闭此选项

You can also turn this option off under 'Page' > 'Compatibility View Settings'

这问题让我朝着正确的方向发展。

This question has put me in the right direction.

编辑:我建议网络开发人员在ie8中选中此选项,因为您的大多数用户都会检查它。这样你就可以在开发周期中发现这些错误。

I advise web developers to leave this option checked in ie8, because most of your users will have it checked. This way you will catch these errors in the development cycle.

EDIT2: sv_in是对的。 IE = edge 更清洁。

sv_in is right. IE=edge is much cleaner.

这篇关于为什么'string'[0]在ie8 + IIS7.5上的行为与其他浏览器或本地文件不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆