views:

64

answers:

2
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

A: 

Is your calling logic executed in the same function-scope as the this.HTMLParser definition?

Try putting an alert statement inside of HTMLParser and see if the call is even made. It sounds like it is throwing an exception and leaving your script.

j0rd4n
j0rd4n, I updated my question.
Delirium tremens
rosscj2533 answered it correctly. 'this' refers to your SiteCompare object but the HTMLParser function is not defined as a member of that object (so it technically doesn't exist). You need to either move it back as a global or define it as a member of the SiteCompare object.
j0rd4n
A: 

The problem is that this is not the same in the function definition and when it's being called. When HTMLParser is defined, this is the SiteCompare object, when this.HTMLParser(searchContents) is called, this is probably the window object. So the error you are getting means that window.HTMLParser is not a function.

To fix this you'd need to define your HTMLParser method outside of the SiteCompare object, or (probably better) use the SiteCompare object to call HTMLParser. Example:

var parser = new SiteCompare();
parsedHTML = parser.HTMLParser(searchcontents); 
rosscj2533