作者blog:www.coolcode.cn
ie 5.5 中的 jscript 版本是 5.5 版,它比以前版本的 jscript 中多了如数组的 push、pop、shift、unshift 方法和 encodeuri、decodeuri 等一些重要的函数。而这些增加的内容在目前其他浏览器(如 moziila/firefox 和 opera)上也同样支持。因此目前开发网站一般对于 ie 浏览器只能兼容到 5.5 版,而对于更低版本的 ie(如 ie 5、ie 4 等),则不再去考虑了。虽然这些低版本的 ie 浏览器目前已经不是主流,但如果能够不需要修改现有代码就能够兼容它们的话,倒是也可以考虑。因此我做了这个兼容低版本 ie 的 jscript 5.5 实现。当然它不可能完全兼容 jscript 5.5,但对于最常用的一些方法,都已经实现了。
该库使用非常简单,只需要在网页的 head 部分加入:
<script type="text/javascript" src="iecompat.js"></script>
就可以了。
完全实现的:
array 对象中:
·push 方法
·pop 方法
·shift 方法
·unshift 方法
·splice 方法
date 对象中:
·todatestring 方法
·totimestring 方法
·tolocaledatestring 方法
·tolocaletimestring 方法
·function 对象中:
·apply 方法
·call 方法
global 对象中:
·undefined 属性
·encodeuri 方法
·encodeuricomponent 方法
·decodeuri 方法
·decodeuricomponent 方法
number 对象中:
·toexponential 方法
·tofixed 方法
·toprecision 方法
对于错误处理,ie 5(jscript 5)中已经有了 try…catch 和 throw 语句,因此 decodeuri、decodeuricomponent、toexponential、tofixed、toprecision、apply 如果出现运行期错误,在 ie 5 上会抛出跟 ie 5.5+ 中一样的错误信息,但是因为 ie 4 没有错误处理语句,如果上述函数出现运行期错误,将会返回 null。注意上面说的运行期错误,不是指上述函数实现中的错误,而是指在这些函数正常工作的情况下应该出现的错误。
其中 function 的 apply 函数的实现参考了:
http://www.openjsan.org/doc/a/ad/adamk/upgrade/0.04/lib/upgrade/function/apply.html
这段程序。
不完全实现的:
error 对象
object 对象中:
·isprototypeof 方法
·hasownproperty 方法
·propertyisenumerable 方法
string 对象中:
·tolocalelowercase 方法
·tolocaleuppercase 方法
·localecompare 方法
因为 ie 4 不具备错误处理语句,因此 error 对象在 ie 4 上并不具备 ie 5 以上 error 对象应具有的功能,因此它对于 ie 4 的实现只能保证你在访问或创建它时不会出错。
object 中的 isprototypeof、hasownproperty 和 propertyisenumerable 方法只是做了模拟实现,其返回值并非总是正确。
string 对象中的 tolocalelowercase、tolocaleuppercase 和 localecompare 方法实际上并没有考虑本地字符集,但在大部分系统上它还是工作正常的。
完全没有实现的:
正则表达式对象中扩充的属性和限定符
下载: iecompat.js
代码拷贝框
[ctrl+a 全部选择 然后拷贝]
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器