如何将整个文档HTML作为字符串? [英] How to get the entire document HTML as a string?
问题描述
<$ 标签中有没有一种方法可以将 html 标签中的整个HTML作为字符串? C $ C> document.documentElement中??。
MS添加了 outerHTML
和 innerHTML
属性。
根据 MDN , outerHTML
在Firefox中受支持11,Chrome 0.2,Internet Explorer 4.0,Opera 7,Safari 1.3,Android,Firefox Mobile 11,IE Mobile,Opera Mobile和Safari Mobile。 outerHTML
位于 DOM解析和序列化规范。
请参阅 quirksmode 以了解浏览器兼容性为什么会为你工作。所有支持 innerHTML
。
var markup = document.documentElement.innerHTML;
alert(标记);
Is there a way in JS to get the entire HTML within the html tags, as a string?
document.documentElement.??
MS added the outerHTML
and innerHTML
properties some time ago.
According to MDN, outerHTML
is supported in Firefox 11, Chrome 0.2, Internet Explorer 4.0, Opera 7, Safari 1.3, Android, Firefox Mobile 11, IE Mobile, Opera Mobile, and Safari Mobile. outerHTML
is in the DOM Parsing and Serialization specification.
See quirksmode for browser compatibility for what will work for you. All support innerHTML
.
var markup = document.documentElement.innerHTML;
alert(markup);
这篇关于如何将整个文档HTML作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!