felix
felix

Reputation: 11552

Javascript Firefox problem

I am trying to execute the following code from a firefox extension but it is not working. The actual code inside the else part was different but even this simple for loop is not getting executed. alert box without the for loop is working. Can someone have any idea about why this is not working. Thanks

window.addEventListener("pageshow",function(e)
    {
        if((document.title.trim()=="Mozilla Firefox") ||
           (document.title.trim()=="New Tab"))
        {
        }
        else
        {
            for(i=0;i<3;i++)
            {
                alert("hi");
            }
        }
    },true);    

Upvotes: 0

Views: 1160

Answers (3)

felix
felix

Reputation: 11552

I Changed the for loop for...in loop and it worked :)

Upvotes: 0

Chris Doggett
Chris Doggett

Reputation: 20777

If it's inside a Firefox extension, try using content.document instead of just document.

EDIT:

var metaTags = content.document.getElementsByTagName("meta");

for(var i = 0; i < metaTags.length; i++) {
    // do something with metaTags[i]
}

Also, if it helps, feel free to look through the source of any of the extensions I've written.

Upvotes: 2

bobince
bobince

Reputation: 536715

document.title.trim()

Are you sure that's what you want? String->trim() is a non-standard JavaScript method so far only available in Firefox 3.1.

Upvotes: 0

Related Questions