Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

javascript - 如何将整个文档HTML作为字符串?(How to get the entire document HTML as a string?)

JS中是否有办法以字符串形式获取html标记内的整个HTML?

document.documentElement.??
  ask by Robinicks translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

MS added the outerHTML and innerHTML properties some time ago.(MS不久前添加了outerHTMLinnerHTML属性。)

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.(根据MDNouterHTML是在Firefox 11,Chrome浏览器0.2,Internet浏览器4.0,歌剧7,Safari浏览器1.3,安卓,Firefox移动11,IE移动,Opera移动,和Safari移动的支持。)

outerHTML is in the DOM Parsing and Serialization specification.(outerHTMLDOM解析和序列化规范中。)

See quirksmode for browser compatibility for what will work for you.(有关适合您的浏览器的兼容性,请参见quirksmode 。)

All support innerHTML .(所有都支持innerHTML 。)
var markup = document.documentElement.innerHTML;
alert(markup);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...