corss browser (last update: 2006-12-29)

这里说的跨浏览器主要指的是IE及Firefox

首先推荐使用或阅读Prototype.js,其中解决了很多IE及firefox下的兼容问题。

然后就是“Javascript的IE和Firefox兼容性汇编”这篇文章。

这里主要记录是一些本人碰到,而上面又没有涉及的问题

  • IE中iframe的onreadystatechange方法,在firefox下没有这个方法,可以用onload来代替。
  1. if (typeof(domFrame.onreadystatechange) != "undefined") {      
  2.     // ie      
  3.     domFrame.onreadystatechange = notify;      
  4. else {      
  5.     // firefox      
  6.     domFrame.onload = notify;      
  7. }      
  8.      
  9. function notify() {      
  10.     alert('iframe内容装载完成');      
  11. }    
  • firefox下在iframe中的页面内嵌在别的页面中,onload后,取不到clientHeight,clientWidth这些值

像上面那个例子,假如在B页面中写onload事件回调方法,在方法中取clientHeight,clientWidth返回值将不正确。
解决方法可以在A页面中来取值或设置

  1. // A页面     
  2. // 将返回B页面的clentWidth, clientHeight     
  3. domFrame.contentWindow.document.body.clientWidth;     
  4. domFrame.contentWindow.document.body.clientHeight;    
  • IE中取元素的颜色值可以使用element.currentStyle.color,firefox下没有currentStyle。可以使用下面方法来代替:
  1. function getCurrentStyle(, ) {   
  2.         if (.currentStyle) {   
  3.             return .currentStyle[];   
  4.         } else if (window.getComputedStyle) {   
  5.              = .replace(/([A-Z])/g, "-$1");   
  6.              = .toLowerCase();   
  7.             return window.getComputedStyle(, "").getPropertyValue();   
  8.         }   
  9.         return null;   
  10.     }  
 

本文相关评论|Comments

 

发表该文评论|Send Comment