I've used the script injection technique to accomplish this in the
past. The problem with it is that if you want to test the presence of
methods using typeof(<function name>) == "function", it doesn't seem
to like working if the function is inside the injected script
file...at least not in IE.
That is incorrect. Perhaps you are trying to test before you inject
it?
Here is a handy function to take a src string and create a script
file. I suppose it could be improved by specifying namespaces...but
What does that mean?
it'll do what you want it to
function jsInsert(src) {
if( document.createElement && document.childNodes ) {
This is an object inference (a form of browser sniffing.) These are
always a bad idea. Detect and test the features required by your
script. You didn't use childNodes here, so you can remove that check.
Also, detecting methods of host objects by boolean type conversion is
a bad idea. See the isHostMethod function in the Code Worth
Recommending repository.
var scriptElem = document.createElement('script');
scriptElem.setAttribute('src',src);
You didn't test for the presence of setAttribute (and as Randy
mentioned, you don't need it for this script.)
scriptElem.setAttribute('type','text/javascript');
document.getElementsByTagName('head')[0]..appendChild(scriptElem);
You didn't test for the presence of gEBTN or appendChild.
} else {
alert('Your browser is not W3C DOM compliant.');
This line illustrates your flawed reasoning. And why would you alert
such a thing? Scripts should not insult the user's chosen browser and
most users will dismiss this message as gobbledygook anyway.
[snip]