简体   繁体   English

如何在iframe中将页面内容获取为JavaScript中的字符串? 我想要一切 <html> 至 </html>

[英]How can I get page content inside an iframe as string in javascript? I want everything from <html> to </html>

I want to get content from an page that loaded in an iframe , edit that content using DOM manipulation and export edited content into a new page. 我想从加载到iframe的页面中获取内容,使用DOM操作编辑该内容并将已编辑的内容导出到新页面中。 But I can't get content from iframe as string so I cannot export it into a new file. 但是我无法从iframe中获取内容作为字符串,因此无法将其导出到新文件中。

Follows a code extraction: 遵循代码提取:

const innerFrame = clientWindow.contentDocument || clientWindow.contentWindow.document;
//Other code
//...
//...
exportFile('new-file.html', innerFrame.innerHTML);

这对我来说是完美的:

document.getElementById('iframe_id').contentWindow.document.body.innerHTML;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM