Take the 2-minute tour ×

I've got a trouble with Chrome5.0.375.70, but FF 3.6.3 and Opera 10.53 are OK. Below is the line of code:

document.getElementById('content').innerHTML = data.documentElement.innerHTML; 

The data object from the code is a document (typeof(data) == 'object') and I've got it by ajax request to chapter01.xhtml:

<!DOCTYPE html [
<!ENTITY D "&#x2014;">
<!ENTITY o "&#x2018;">
<!ENTITY c "&#x2019;">
<!ENTITY O "&#x201C;">
<!ENTITY C "&#x201D;">
<title>Alice's Adventures in Wonderland by Lewis Carroll. Chapter I: Down the Rabbit-Hole</title>
<link rel="stylesheet" type="application/vnd.adobe-page-template+xml" href="page-template.xpgt"/>
<div class="title_box">
<h2 class="chapnum">Chapter I</h2>
<h2 class="chaptitle">Down the Rabbit-Hole</h2>

The Chrome cuts all before body and as a result link to css in header is missed; user can't see formatted text and images.

How can I fix it or bypass?

P.S. I try to put chapter01.xhtml into div which is contained by <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

share|improve this question
You're using an HTML5 doctype, but you say it's XHTML. Are you really trying to stick a complete <html>...</html> body into the middle of another document? If you check your XHTML DTD, you'll find that you can't do that ... –  Pointy Jun 15 '10 at 18:23
I try to put that chapter01.xhtml into div which is contained by <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;. Where can I check the info you have pointed me out? (Because I am weak at it) –  despero Jun 15 '10 at 18:41
are you trying to "nest" HTML documents like this: <html><body><div><html><body></body></html></div></body></html>? Because thats not allowed –  David Murdoch Jun 15 '10 at 18:48
Yep. The problem is that it works in FF and Opera. Where/How to check the restriction? –  despero Jun 15 '10 at 18:52
don't use innerHTML –  Jarrod Roberson Jun 15 '10 at 19:18
show 1 more comment

3 Answers

.innerHTHML is NON STANDARD and is a bad practice and is browser implementation dependent and should not be used. Especially with XHTML it isn't supported.

share|improve this answer
@lark - that section is specific to HTML which proves @fuzzy's point. –  John K Jun 15 '10 at 19:27
Correct, it is "standardized" whatever that means within the w3c on HTML. I am just confused as to why innerHTML should be avoided. jQuery the popular framework you may have heard of, uses it quite extensively. Granted there is a time and place for anything in the web, discouraging the use of innerHTML is foreign to me. –  tbranyen Jun 15 '10 at 19:33
Just because jQuery uses something doesn't automatically make it a good idea. –  Tim Down Jun 15 '10 at 23:32
if you are going to do XHTML, innerHTML is an especially bad practice, like most shortcuts, it is a hacky short sighted propertiery thing that everyone in a fit of bad judgement decided to support. –  Jarrod Roberson Jun 16 '10 at 1:36
show 3 more comments

I had a similar situation where I wanted to filter DOM elements and the best way I found was to use a mix of DOMParser and XmlSerializer found here:


This is a reasonable cross browser method.

Edit: To elaborate a bit more, you would load in the html string to the DOMParser and be able to work with the DOMDocument as you normally would, then you could use XmlSerializer or the IE equivalent to pump out the new markup.

share|improve this answer
Actually I have 2 types of data objects: first is the document and second is a string (like "<html><body><div></div></body></html>"). The second one I handled by a trick (jQuery): var hiddendiv = $('<div/>'); hiddendiv.html(data); $('#content').html(hiddendiv.html()); The trick works good, but the first (document) is a bit uncontrollable. –  despero Jun 15 '10 at 19:40
If you set that content in a div you will have nothing but issues. Since "most" browser implementations will strip out <body>, <html> and <head> tags. I would recommended using a DOMDocument like I suggested. –  tbranyen Jun 15 '10 at 19:44
Thanks for your answer. It seems a bit complicated, but I will investigate the idea. –  despero Jun 15 '10 at 19:54
add comment

document.getElementById('content').innerHTML = data;

share|improve this answer
document.getElementById('content').innerHTML = data; // sorry, it doesn't work because Chrome outputs "[object Document]" instead of required content. –  despero Jun 15 '10 at 18:48
add comment

Your Answer


