Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15695
| Path | csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Bwig Zomberi <zomberi@email.invalid> |
| Newsgroups | comp.lang.javascript |
| Subject | How to correctly add IE support for standard but missing function |
| Date | Wed, 05 Sep 2012 10:07:56 +0530 |
| Organization | Aioe.org NNTP Server |
| Lines | 61 |
| Message-ID | <k26kv4$dbk$1@speranza.aioe.org> (permalink) |
| NNTP-Posting-Host | oj9c2RgaGvelpMTZmCqlMQ.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120826 Firefox/15.0 SeaMonkey/2.12 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.javascript:15695 |
Show key headers only | 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
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