style513 / reallysimplehistory

Automatically exported from code.google.com/p/reallysimplehistory
Other
0 stars 0 forks source link

Doesn't play nice with other components that insert into the HEAD element #76

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Install RSH
2. Execute other component activities (e.g., Google Maps, my hacked 
version of JSONscriptRequest) that add elements (e.g, script elemnents) to 
the end of the HEAD
3. Attempt to remove such an element from the HEAD using .removeChild

What is the expected output? What do you see instead?

I expect the added script element to be removed; instead I get a 
Javascript error. 

What version of the product are you using? On what operating system?

rsh_0.6

Please provide any additional information below.

The Javascript error arises because the HEAD (into which I inserted the 
script element) is not in fact the script element's parent: its parent is 
the FORM inserted by RSH. This may be because of the way the DOM has been 
mangled by the document.write.

Brian has noted (http://www.pathf.com/blogs/2007/10/dom-methods-doc/) 
that 
"I originally wrote that if you've got script-generated DOM elements 
that need to be treated as native to the document (so, for instance, 
you can persist form values across an entire session regardless of 
whether you navigate off-site), you must use document.write to insert 
them into the DOM. Not true, as it turns out. It doesn't matter 
whether you call document.write or standard DOM methods from the head 
of your document. Either way, both methods seem to result in "native" 
HTML form fields that can properly persist values. Looking at Firebug 
or Opera's developer console, you can see that these elements end up 
being children of the body element even though they were, in fact, 
inserted into the head element. Modern browsers are so smart!" 

Too smart by half. In IE6 at least, the TEXTAREA does end up in the 
body, but the FORM element that (in some sense) contains it remains in 
the HEAD. The DOM structure seems hopelessly confused at this point, 
and other components that add elements to the HEAD (Google Maps and a 
modified version of JSONscriptRequest, in my case) end up with them 
inside that FORM element.  OK as long as you don't try to remove them 
from the HEAD element, where you thought you put them. If you do: 
Javascript error. 

Would this behave better if rsh was using DOM methods rather than 
document.write? Or am I missing something?

Original issue reported on code.google.com by Shona.Do...@gmail.com on 5 Jan 2009 at 2:01

GoogleCodeExporter commented 8 years ago
I should have added that this only causes a JS error with IE6, as far as I know.

Original comment by Shona.Do...@gmail.com on 5 Jan 2009 at 2:29