Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Safari - innerHTML replacement and DOM exceptions



On 21 Apr 2004, at 12:48, Peter-Paul Koch wrote:

Whenever I try to replace anything in the DOM with innerHTML in Safari, I get "(event handler):DOM exception 7" in the Console, which means I'm not allowed to alter it.

Why should this be? There's a page on O'Reilly that charts dynamic table generation http://www.oreillynet.com/javascript/2003/05/06/examples/ dyn_table_benchmarker_ora.html which cites results for doing this, so it must be possible.
Can anyone confirm this for me?
If you have a spare minute try the link above and hit the "Approach #3" button to see if it works for you or not.

The problem is not that innerHTML doesn't work (it works fine), but that Safari can't handle writing the innerHTML of a <tbody> tag. If you write the entire table (including <table> and <tbody>) in the innerHTML string it works fine.


See my tests at http://www.quirksmode.org/dom/innerhtml.html for a working example. (Incidentally, I come to the opposite conclusion as Goodman: innerHTML is faster than pure W3C DOM).

Ah, that was you :)
Your tests helped me a great deal in getting to grips with this DOM thing, which is new ground for me.
Thanks for publishing, they really were very valuable indeed.


I've discovered some more weird behavior too, so let me explain what it is that I'm trying to do.

I'm trying to replicate the behavior of a disclosure box, so that I can hide a form inside it and have it shown when the user clicks the disclosure triangle in the box, much like a Mac OS interface thing.

Using the W3C DOM method worked for me, but I discovered that once the box had been closed and reopened, I couldn't reference any of the form elements any more.

After trying many alternatives to grab a hold on the form elements (id's, referring by index number on the form etc) I discovered that part of the reason was to do with that when Safari removes the rows in the table, it still has some internal reference to them somewhere.

So, everytime you close the box (remove the rows) then open the box again, you are effectively adding more and more rows to the table (even though you can only see the rows you've just added). In my case, if I wanted to access document.form1[0] it'd be fine the first time the box was opened, but subsequent times the index would be added to by the number of elements in the box.

To remedy this, I tried your method of re-writing the entire table in one go, and it works a treat.

I suspect all this has something to do with the problems of Safari getting slower and slower everytime you repeated your tests - the first time you rendered your table there were 50 rows, but on subsequent repeat tests, Safari's internal representation of the table was increasing by 50 rows each time.

You can see this in action here:
http://www.moremasters.com/domTest/W3CDOM.html

and the innerHTML version which works as expected is here:
http://www.moremasters.com/domTest/innerHTML.html

Obviously these are quick and dirty tests, so forgive the lack of comments etc.

Cheers
Ian
_______________________________________________
web-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/web-development
Do not post admin requests to the list. They will be ignored.


References: 
 >RE: Safari - innerHTML replacement and DOM exceptions (From: "Peter-Paul Koch" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.