Bug 15648 - It is not possible to modify the innerHTML of a HEAD element
Summary: It is not possible to modify the innerHTML of a HEAD element
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 523.x (Safari 3)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-23 17:08 PDT by Kevin Decker
Modified: 2023-08-23 07:35 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Decker 2007-10-23 17:08:45 PDT
Other browsers let you modify the innerHTML of a head element, but WebKit does not. Modifying the innerHTML of head elements is important for a high profile email site.
Comment 1 David Gatwood 2009-11-28 07:59:39 PST
It's far worse than that.  It is not possible to even add elements into the HEAD tag programmatically unless there is already at least one element inside that tag, AFAICT.

Steps to reproduce:

* Create an iframe element in the HTML.
* Populate the iframe by setting iframeelt.contentDocument.body.innerHTML = "...."
* Set var elt = iframeelt.contentDocument.getElementsByTagName('head')[0];
* Note that the head element was correctly created implicitly.
* Try to add stuff to elt.
* Observe the DOM error 7 (NO_MODIFICATION_ALLOWED_ERR).

Also tried various other ways of loading the content, including putting a HEAD tag in the BODY, putting the LINK tags in the body where they should have been automatically moved into the HEAD, etc.  Nothing worked.

This behavior makes it much, much more difficult to write any code that uses iframes and apply CSS styles to the content.  Combine that with 31951 and it forced some really ugly workarounds.  I eventually gave up and used the src attribute to load a real HTML file that contained a HEAD element with the tags I needed inside it, then blowing out the BODY.
Comment 2 Alexey Proskuryakov 2009-11-30 17:05:11 PST
> It's far worse than that.  It is not possible to even add elements into the
> HEAD tag programmatically unless there is already at least one element inside
> that tag, AFAICT.

I made a test case from this description, but it works fine. I was able to successfully insert a LINK element inside an empty auto-created HEAD.

In any case, let's not discuss this here. Difficulties with manipulating HEAD content via DOM Core APIs would likely have a different cause than innerHTML, and this bug is about the latter. Please file a new bug if you have a test case that works in Firefox, but not in Safari.