D
David Mark
David Mark said the following on 12/5/2007 10:11 AM:
Not in that one. That one is designed to catch browsers that will
execute scripts inserted via innerHTML. The only browser that needs the
leading space is IE and it doesn't execute them so it isn't needed
there. Meaning, IE is going to ignore it either way so it doesn't matter.
Makes sense, assuming that IE is the only one that has that issue
(which wouldn't surprise me.)
I was trying to keep mine as simple as I could. The fewer "tricks" you
use to try to do it, the better your chance of success. Or that was my
thinking anyway. Doesn't make me right though
You are correct. The reason I made a wrappers for inner/outerHTML has
to do with other issues (like losing events when adding HTML, setting
the HTML of TBODY and SELECT elements, etc.) So it makes sense for me
to test against the functions I use. For a gp test of the innerHTML/
script issue, it makes sense to keep variables to a minimum. So far I
haven't seen any difference between the two sets of test results, but
then I haven't tested in as many browsers.
else
{
if(isIE)
{
newScript.text = d[x].text;
}
This is where mine differs. I create an array of functions to try,
based on testing the text and canHaveChildren properties of a created
script element, then try them in turn. The first one that works is
the one used in the innerHTML wrapper. I try the text property first,
which may or may not be good idea. Does that property throw errors in
any agents that support createTextNode? If so, I will have to change
the testing order.
iCab, Safari2/Mac and some other fringe browsers error if you try to set
the .text property of a script element but using createTextNode works in
those two browsers. The main reason I used the isIE is because IE is the
only browser I am aware of that doesn't support createTextNode and the
idea was to use createTextNode and only use .text for IE.I switched the order of testing to try createTextNode first.
As an afterthought, I am not sure what will happen in them if you try
if(scriptElement.text) to test the property. The results page doesn't
attempt any feature detection at all because I wanted to know if the
browser supported the feature itself by trying to set it instead of
testing for it. That is how I found out about createTextNode and IE. It
will pass a feature detection test for it but falls down when you try to
use it.
I see. Perhaps the order wouldn't have mattered as the text property
may not be defined in those odd Mac browsers. Then again, it probably
is, otherwise I can't see it throwing an error.
I have it marked so I can look at it more in-depth when I have time.
Right now trying to get out of town again for the weekend.
It has gotten to the point where it is more of a mental exercise now. I
don't have either of them. The test results I have are from other people
(mostly RobG, Richard and Peter). I don't think that either one of them
is going to fall down with an AJAX application because you have to worry
about AJAX support first and just about any AJAX-capable browser should
be able to handle setting the .text or .src of a script element.
One would hope. Then again, any browser that can instantiate an
ActiveX object is a potential Ajax client. It seems like that would
include even IE3. Probably not in reality, but I am not sure what
would stop it. Unlike IE4, I do have a working IE3 installed here.
I'll have to try that some time.