I have a function that is intended to count the occurrences of each word on a web page (from the same domain) I've read numerous posts about getting the innerhtml of an iframe, however I think I'm misunderstanding as this isn't working, and is just giving me an empty string. TagID is the location in my HTML doc I want to add these items to.
function filereader(tagID) {
var x = document.getElementById(tagID);
var newFrame = document.createElement("iframe");
newFrame.id = "pageinframe";
newFrame.src = document.getElementById("pagetoread").value;
x.appendChild(newFrame);
var innerDoc = document.getElementById("pageinframe");
var innerDocContent = innerDoc.contentDocument.body.innerHTML;
console.dir(innerDocContent);
var split = innerDocContent.split(" "), obj = {};
var y = document.createElement("p");
for (var x = 0; x < split.length; x++) {
if(obj[split[x]] == undefined) {
obj[split[x]] = 1;
}
else {
obj[split[x]]++;
}
}
console.dir(obj);
for (var i= 0; i < obj.length; i++) {
var toadd = document.createTextNode(obj[i]);
y.appendChild(toadd);
}
var x = document.getElementById(tagID);
x.appendChild(y);
}