Dec 30, 2006
这里说的跨浏览器主要指的是IE及Firefox
首先推荐使用或阅读Prototype.js,其中解决了很多IE及firefox下的兼容问题。
然后就是“Javascript的IE和Firefox兼容性汇编”这篇文章。
这里主要记录是一些本人碰到,而上面又没有涉及的问题
- IE中iframe的onreadystatechange方法,在firefox下没有这个方法,可以用onload来代替。
- if (typeof(domFrame.onreadystatechange) != "undefined") {
- // ie
- domFrame.onreadystatechange = notify;
- } else {
- // firefox
- domFrame.onload = notify;
- }
- function notify() {
- alert('iframe内容装载完成');
- }
- firefox下在iframe中的页面内嵌在别的页面中,onload后,取不到clientHeight,clientWidth这些值
像上面那个例子,假如在B页面中写onload事件回调方法,在方法中取clientHeight,clientWidth返回值将不正确。
解决方法可以在A页面中来取值或设置
- // A页面
- // 将返回B页面的clentWidth, clientHeight
- domFrame.contentWindow.document.body.clientWidth;
- domFrame.contentWindow.document.body.clientHeight;
- IE中取元素的颜色值可以使用element.currentStyle.color,firefox下没有currentStyle。可以使用下面方法来代替:
- function getCurrentStyle(, ) {
- if (.currentStyle) {
- return .currentStyle[];
- } else if (window.getComputedStyle) {
- = .replace(/([A-Z])/g, "-$1");
- = .toLowerCase();
- return window.getComputedStyle(, "").getPropertyValue();
- }
- return null;
- }



本文相关评论|Comments