简体   繁体   中英

Chrome extension fails when detecting iframes

Basically what i am trying to do is to detect number of frames which are contained within the G+ home page, and off course i do use a content script

The Js file for the extension:

var myIframes;
window.addEventListener('load'
,function()
{
    //If the window location matches the G+ home page
    //Log number of frames contained within it
    if(window.location.href.match("https://plus.google.com/u/0/"))
    {
        console.log('G+ loaded');

        myIframes = document.getElementsByTagName('iframe');
        console.log(myIframes.length);
    }
}
,false);

The o/p log of executing this code is:

G+ loaded

2

Now comes the strange part, when i try to access the myIframes variables length from within the inspector console, i got 8 frames.

So my question is "How come !." , shouldn't the myIframes variables stay as it was when it first get evaluated ?

document.getElementsByTagName('iframe') returns a nodeList.

nodeLists are live , they will update when the DOM changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM