如何将整个文档HTML作为字符串? [英] How to get the entire document HTML as a string?

查看:113
本文介绍了如何将整个文档HTML作为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ 标签中有没有一种方法可以将 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屋!

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