我可以使用以下方式打印整个文件内容:
write(document.getElementById('iframe').contentDocument.body.firstChild.innerHTML);
但是如何逐行检索和打印文件内容?
答案 0 :(得分:0)
您可以使用拆分功能和分隔符“\ r \ n”或“\ n”来提取已加载内容中的所有单独行,然后执行您要执行的任何操作它们:
var text = document.getElementById('iframe').contentDocument.body.firstChild.innerHTML;
var lines = text.split("\n"); // this will extract all the lines
for (i=0; i<lines.length; i++) { // this will move over all the lines
var current_line = lines[i]; // this contains every line at its turn
// do here what ever you want to do with current_line
}