views:

114

answers:

3

Hi! 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:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html [
<!ENTITY D "&#x2014;">
<!ENTITY o "&#x2018;">
<!ENTITY c "&#x2019;">
<!ENTITY O "&#x201C;">
<!ENTITY C "&#x201D;">
]>
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>Alice's Adventures in Wonderland by Lewis Carroll. Chapter I: Down the Rabbit-Hole</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="stylesheet" type="application/vnd.adobe-page-template+xml" href="page-template.xpgt"/>
</head>
<body>
<div class="title_box">
<h2 class="chapnum">Chapter I</h2>
<h2 class="chaptitle">Down the Rabbit-Hole</h2>
<hr/>
</div>

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"&gt;

A: 

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

kennebec
document.getElementById('content').innerHTML = data; // sorry, it doesn't work because Chrome outputs "[object Document]" instead of required content.
Desperadeus
A: 

.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.

fuzzy lollipop
It isn't? http://www.w3.org/TR/2008/WD-html5-20080610/dom.html#innerhtml0
lark
@lark - that section is specific to HTML which proves @fuzzy's point.
John K
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.
lark
Just because jQuery uses something doesn't automatically make it a good idea.
Tim Down
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.
fuzzy lollipop
Do either of you care to elaborate on your replies. Tim, granted not *everything* jQuery does is a good idea, it obviously has bugs... but do you care to extend on any possible bugs that could incur with the use of it? Same fuzzy, you claim its a short sighted proprietary thing, but yet you have nothing to back up your claims that it is a bad idea to use. In most cases its the only performant way to load in external content.
lark
just google it, even in the link you posted has lots of limitations, like it doesn't execute script tags, it __ONLY__ works as HTML, just the fact that it has all those rules for parsing and failures and side effects just SCREAMS crap. The fact that the browsers all implement it differently, I could go on, but google does a great job of that. If you are happy with using it and the buggy cross platform limitations to just HTML the go for it. I don't have time for that kind of drama. The __single__ that this question is being asked is enough of a reason to make it a bad practice.
fuzzy lollipop
And "faster" isn't a good argument, since the times for something like this are measured in at most double digit milliseconds differences.
fuzzy lollipop
A: 

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:

http://www.hiteshagrawal.com/javascript/convert-xml-document-to-string-in-javascript

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.

lark
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.
Desperadeus
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.
lark
Thanks for your answer. It seems a bit complicated, but I will investigate the idea.
Desperadeus