yeungsprite
Programmer
Hello,
I am having trouble creating a javascript function to parse through the HTML source code of a webpage using the Firefox browser. I have the following code, which attempts to make use of the built in function calls 'window.document.body.innerHTML' and 'HTMLsource.indexOf('bug.gif', startIndex)', but there is something wrong with the syntax. Can anyone suggest any tips or other calls to make to achieve the same result?
Thanks!
function CountBugs()
{
var startIndex, bugCount, CurrIndex, HTMLsource;
bugCount=0;
startIndex=1;
// DEBUG - does not store HTML code
HTMLsource=window.document.body.innerHTML;
while (1)
{
//starting at startIndex, look for index of string 'bug.gif'
CurrIndex=HTMLsource.indexOf('bug.gif', startIndex);
if (CurrIndex < 0 || startIndex > HTMLsource.length - 5)
{
alert("There are " + bugCount + " bugs on this page");
return bugCount;
}
//update CurrIndex to index of bug gif , but make sure you go to the next character to avoid an infinite loop
startIndex=CurrIndex + 1;
bugCount++;
}
}
I am having trouble creating a javascript function to parse through the HTML source code of a webpage using the Firefox browser. I have the following code, which attempts to make use of the built in function calls 'window.document.body.innerHTML' and 'HTMLsource.indexOf('bug.gif', startIndex)', but there is something wrong with the syntax. Can anyone suggest any tips or other calls to make to achieve the same result?
Thanks!
function CountBugs()
{
var startIndex, bugCount, CurrIndex, HTMLsource;
bugCount=0;
startIndex=1;
// DEBUG - does not store HTML code
HTMLsource=window.document.body.innerHTML;
while (1)
{
//starting at startIndex, look for index of string 'bug.gif'
CurrIndex=HTMLsource.indexOf('bug.gif', startIndex);
if (CurrIndex < 0 || startIndex > HTMLsource.length - 5)
{
alert("There are " + bugCount + " bugs on this page");
return bugCount;
}
//update CurrIndex to index of bug gif , but make sure you go to the next character to avoid an infinite loop
startIndex=CurrIndex + 1;
bugCount++;
}
}