Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15695

How to correctly add IE support for standard but missing function

From Bwig Zomberi <zomberi@email.invalid>
Newsgroups comp.lang.javascript
Subject How to correctly add IE support for standard but missing function
Date 2012-09-05 10:07 +0530
Organization Aioe.org NNTP Server
Message-ID <k26kv4$dbk$1@speranza.aioe.org> (permalink)

Show all headers | View raw


Hi Group,

Some versions of IE do not support certain DOM methods and properties
available in all other browsers. I wish to add support for these API in
a single function call so that the rest of my JS code is free of JS
hacks.


Here is my code. There must be a simpler way than adding the missing
methods and properties to every element in the page.


function fixIE() {
   var i, n;

   var oAllElements = document.getElementsByTagName("*");
   n = oAllElements.length;

   if (!document.getElementsByClassName) {
     for (i = 0; i < n; i++) {
       oAllElements[i].getElementsByClassName =
         myGetElementsByClassName;
     }
     document.getElementsByClassName =
        myGetElementsByClassName;
   }

   if (!document.getElementsByTagName("body")[0].textContent) {
     for (i = 0; i < n; i++) {
       oAllElements[i].textContent =
          oAllElements[i].innerText;  // innerText works for me
     }
   }
}



function myGetElementsByClassName(sClassName) {

   var oAllElements = this.getElementsByTagName('*');
   var aMatchingElements = [];
   var i, n;
   n = oAllElements.length;

   for(i = 0; i < n; i++){
     if (
           (oAllElements[i].className == sClassName) ||
           ((' ' + oAllElements[i].className + ' ').indexOf(sClassName) 
 > -1) ||
           ((' ' + oAllElements[i].className).indexOf(sClassName,
             oAllElements[i].className.length - sClassName.length) > -1)
         ) {
       aMatchingElements.push(oAllElements[i]);
     }

   }

   return aMatchingElements;

}

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

How to correctly add IE support for standard but missing function Bwig Zomberi <zomberi@email.invalid> - 2012-09-05 10:07 +0530
  Re: How to correctly add IE support for standard but missing function David Mark <dmark.cinsoft@gmail.com> - 2012-09-05 04:37 -0700
    Re: How to correctly add IE support for standard but missing function Bwig Zomberi <zomberi@email.invalid> - 2012-09-06 09:36 +0530

csiph-web