Subject: JavaScript problem getting page content with no fields
Certainly, but it is a heck of a lot easier if you can be sure that the browser you are using is more-or-less DOM1-compliant. That is, if you can use the following properties/methods:
.getElementsByTagName()
.childNodes
.parentNode
If you can use these methods (supported in IE5+, NS6+, Mozilla, Opera 6+, Safari, and all of the recent open-source browsers that I’m aware of) and can know the structure of the page, then you can get or set the information on the page. If the designer has been kind enough to include id attributes, then it gets even easier. Let’s assume that s/he didn’t, though, and that you want to change the style of the fourth cell in the second row of the third table to white text on a red background, then prompt the text it contains:
var allTables = document.getElementsByTagName(‘table’);
//gets all of the tables
var rowsInTableThree = allTables[2].getElementsByTagName(‘tr’);
//gets all rows in the third table – remember index is zero-based
var cellsInRowTwo = rowsInTableThree.getElementsByTagName(‘td’);
var cellFour = cellesInRowTwo[3];
cellFour.style.backgroundColor = ‘#ff0000’;
cellFour.style.color = ‘#ffffff’;
var kiddies = cellFour.childNodes();
var bigString = ‘’;
for (i=0;i<kiddies.length;i++) {
if(kiddies[i].type = 3) {
//3 is a text node
bigString += kiddies[i].data;
}
}
alert(bigString)