Can't use Firefox innerHTML() on XHTML page?
GregH <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <7ae1c421-ac1e-41a8-ba23-69652d425ab0@f18g2000vbf.googlegroups.com> |
Hi,
I've written a very simple bookmarklet, which uses innerHTML to create
new DOM elements on a webpage:
(function(){
var testDiv = document.createElement( 'div' );
testDiv.innerHTML = "<p>I don't display</p>";
document.body.appendChild(testDiv);
})()
For easy copying into a bookmark:
javascript:(function(){var%20testDiv=document.createElement
('div');testDiv.innerHTML="<p>I%20don't%20display</
p>";document.body.appendChild(testDiv);})()
Unfortunately, in Firefox 3.0.8, this bookmarklet blows up when
applied on this XHTML webpage: http://direct.tesco.com/q/R.200-3522.aspx
The Firebug error is:
uncaught exception: [Exception... "Component returned failure code:
0x80004003 (NS_ERROR_INVALID_POINTER)
[nsIDOMNSHTMLElement.innerHTML]" nsresult: "0x80004003
(NS_ERROR_INVALID_POINTER)" location: "JS frame :: javascript:
(function(){var%20testDiv=document.createElement
('div');testDiv.innerHTML="<p>I%20don't%20display</
p>";document.body.appendChild(testDiv);})() :: anonymous :: line 1"
data: no]
Can anyone explain why this doesn't work?
I initially thought that the Firefox innerHTML function couldn't be
executed when rendering an xhtml+xml document in standards compliance
mode. However, I successfully ran this bookmarklet against an xhtml
test document rendered from my webserver with a reponse header of
'application/xhtml+xml; charset=utf-8'.
This bookmarklet does not blow up for Safari 3.2.1 and Chrome
1.0.154.53
Any suggestions would be much appreciated.
Greg