Collect DOM elements from external HTML documents
Posted
by sonofdelphi
on Stack Overflow
See other posts from Stack Overflow
or by sonofdelphi
Published on 2010-04-29T12:36:20Z
Indexed on
2010/04/29
14:17 UTC
Read the original article
Hit count: 271
JavaScript
|dom
I am trying to write a report-generator to collect user-comments from a list of external HTML files. User-comments are wrapped in < span> elements.
Can this be done using JavaScript?
Here's my attempt:
function generateCommentReport()
{
var files = document.querySelectorAll('td a'); //Files to scan are links in an HTML table
var outputWindow = window.open(); //Output browser window for report
for(var i = 0; i<files.length; i++){
//Open each file in a browser window
win = window.open();
win.location.href = files[i].href;
//Scan opened window for 'comment's
comments = win.document.getElementsByName('comment');
for(var j=0;j<comments.length;j++){
//Add to output report
outputWindow.document.write(comment[i].innerHTML);
}
}
}
© Stack Overflow or respective owner