开发者

Javascript: Why is this JS stopping? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_开发问答

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

This is for a Firefox addon, its a bit puzzling as after a certain point no code is being executed.

if (self.xmlDoc == null) return false;


    var domain_and_full_destination=processing_domain.split("  ");

    if(domain_and_full_destination[0]=="xxx.org")
    {
        //window.stop(); // Totally stop the page from loading.

        self.root_node = '';
        self.root_node = self.xmlDoc.getElementsByTagName('joe_biden_is_a_moron');
        var destinations_array= new Array();

        for (var cci = 0; cci <= self.root_node.length; cci++)
        {
            self.second_node = '';
            self.second_node = self.root_node[cci];
            destinations_array[cci]=self.second_node.getElementsByTagName('riaum')[0].firstChild.nodeValue;
        }


alert(domain_and_full_destination[0]+"\n");

The if goes on, but I cut it short because I want to know why the alert is never getting called?

Putting my alert in the for loop gets called, but anything after the for loop never executes.

No errors in the Firefox error console either.


Are you sure it's not throwing? You're doing something wrong there.

for (var cci = 0; cci <= self.root_node.length; cci++)

should be

for (var cci = 0; cci < self.root_node.length; cci++)

The fact that you used <= there means that, on the last iteration of the loop, self.second_node is actually set to undefined, which would make self.second_node.getElementsByTagName('riaum') throw an exception.


missing a close bracket for if statement...?

Ivo Stoykov


You mention that for loop gets called but can you alert just before for loop ends to see if it iterates / exits the loop.

Placing alerts can help you debug if you are a beginner and do not know how to use debugging tools. However in the longer run you may want to use these tools to help you get the job done much faster.


try to devide this line into few variables

destinations_array[cci]=self.second_node.getElementsByTagName('riaum')[0].firstChild.nodeValue;

i.e.

var riaum = self.second_node.getElementsByTagName('riaum')[0] || null;
var child = riaum.firstChild || '';
var nodeVal = child.nodeValue || '?';
destinations_array[cci]=nodeVal;

you have to add checks what's in vars...

HTH

Ivo Stoykov

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜