function sc_HTMLParser(aHTMLString){
var parseDOM = content.document.createElement('div');
parseDOM.appendChild(Components.classes['@mozilla.org/feed-unescapehtml;1']
.getService(Components.interfaces.nsIScriptableUnescapeHTML)
.parseFragment(aHTMLString, false, null, parseDOM));
return parseDOM;
}
becomes
this.HTMLParser = function(aHTMLString){
var parseDOM = content.document.createElement('div');
parseDOM.appendChild(Components.classes['@mozilla.org/feed-unescapehtml;1']
.getService(Components.interfaces.nsIScriptableUnescapeHTML)
.parseFragment(aHTMLString, false, null, parseDOM));
return parseDOM;
}
and
searchcontents = req.responseText;
parsedHTML = sc_HTMLParser(searchcontents);
sitefound = sc_sitefound(compareuris, parsedHTML);
becomes
searchcontents = req.responseText;
alert(searchcontents);
parsedHTML = this.HTMLParser(searchcontents);
alert(parsedHTML);
sitefound = this.sitefound(compareuris, parsedHTML);
The modular code alerts the search contents, but doesn’t alert the parsedHTML. Why? How to solve?
UPDATED:
j0rd4n, it’s:
function SiteCompare() {
this.finishSiteCompare = function(downloaduris, compareuris, tryinguri) {
// code
searchcontents = req.responseText;
alert(searchcontents);
parsedHTML = this.HTMLParser(searchcontents);
alert(parsedHTML);
sitefound = this.sitefound(compareuris, parsedHTML);
// code
}
this.HTMLParser = function(aHTMLString) {
//code
}
}
The call is not even being made.
UPDATE:
the Error Console says this.HTMLParser is not a function
The problem is that
thisis not the same in the function definition and when it’s being called. WhenHTMLParseris defined, this is theSiteCompareobject, whenthis.HTMLParser(searchContents)is called,thisis probably the window object. So the error you are getting means thatwindow.HTMLParseris not a function.To fix this you’d need to define your
HTMLParsermethod outside of theSiteCompareobject, or (probably better) use theSiteCompareobject to callHTMLParser. Example: