T
Trenqo 0
Instead of doing repetitive checks throughout my code, or defining new
methods that won't work unless they are included, I have taken the
approach of redefining existing methods in order to make them as cross
browser compatible as possible.
For example:
if(!document.getElementById)
{
if(document.all)
document.getElementById = function(id) { return document.all[id]; }
else if(document.layers)
document.getElementById = function(id) { return
document.layers[id]; }
else
browserUnsupported()
}
I have a few other similar methods in a crossbrowser.js file, which I
include in every html file I create.
However, I am stumped on how to make a similar redefined method for
"addEventListener" and other methods to be added to each html element.
I was hoping to be able to add it through a prototype to the root
HTMLElement type. Unfortunately, that doesn't seem to propagate the
changes to all the subtypes such as "span" (HTMLSpanElement). I can
however add it directly to the HTMLSpanElement and it works.
I guess that I can make an array of all the element prototypes, and
then cycle through that adding whatever methods I want to each element.
However, if there is a better, less kludgy way to do this, I'd like to
know about it.
Also, I'm curious of other's opinions of this approach and its
disadvantages compared to traditional cross browser compatibility
approaches.
Finally, if someone else has done something similar, it could be very
helpful if they uploaded to linked to their code, so that I don't
repeat something that has already been done.
methods that won't work unless they are included, I have taken the
approach of redefining existing methods in order to make them as cross
browser compatible as possible.
For example:
if(!document.getElementById)
{
if(document.all)
document.getElementById = function(id) { return document.all[id]; }
else if(document.layers)
document.getElementById = function(id) { return
document.layers[id]; }
else
browserUnsupported()
}
I have a few other similar methods in a crossbrowser.js file, which I
include in every html file I create.
However, I am stumped on how to make a similar redefined method for
"addEventListener" and other methods to be added to each html element.
I was hoping to be able to add it through a prototype to the root
HTMLElement type. Unfortunately, that doesn't seem to propagate the
changes to all the subtypes such as "span" (HTMLSpanElement). I can
however add it directly to the HTMLSpanElement and it works.
I guess that I can make an array of all the element prototypes, and
then cycle through that adding whatever methods I want to each element.
However, if there is a better, less kludgy way to do this, I'd like to
know about it.
Also, I'm curious of other's opinions of this approach and its
disadvantages compared to traditional cross browser compatibility
approaches.
Finally, if someone else has done something similar, it could be very
helpful if they uploaded to linked to their code, so that I don't
repeat something that has already been done.