innerHTML的不正确使用XHTML的浏览器工作 [英] innerHTML doesn't work correctly with xhtml in Chrome

查看:150
本文介绍了innerHTML的不正确使用XHTML的浏览器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与Chrome5.0.375.70,一个麻烦,但FF 3.6.3和歌剧 10.53都OK。下面是code线:

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; 

数据从code对象是文档(typeof运算(数据)=='对象'),我已经得到它通过Ajax请求的 chapter01.xhtml

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

在Chrome浏览器削减所有正文之前结果链接 CSS 在头文件是错过;用户看不到格式的文本和图像。

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.

我如何解决或绕过?

P.S。我试图把 chapter01.xhtml 成包含由格&LT; D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENHTTP! //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

推荐答案

我是使用的DOMParser的搭配了类似的情况,我想过滤的DOM元素,我发现最好的方法和XmlSerializer的发现这里:

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.

编辑:为了详细一​​点,你会加载HTML字符串到的DOMParser和能够与DOM文档的工作,你通常会,那么你可以使用XmlSerializer的或IE相当于泵出新的标记。

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.

这篇关于innerHTML的不正确使用XHTML的浏览器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆