Question: i have simple chrome extension that opens JQuery dialog box on each tab i open ,  

the problem is when web page has iframe in it , the dialog box opens as many iframes are in the page .  

i want to avoid this , all i need it open only and only 1 instance of the Dialog box for each page .
how can i avoid the iframes in the page ?  

this is my content script :

```
var layerNode= document.createElement('div');
    layerNode.setAttribute('id','dialog');
    layerNode.setAttribute('title','Basic dialog');
var pNode= document.createElement('p');
    console.log("msg var: "+massage); 
    pNode.innerHTML  = massage;

layerNode.appendChild(pNode);
document.body.appendChild(layerNode);

jQuery("#dialog").dialog({
    autoOpen: true, 
    draggable: true,
    resizable: true,
    height: 'auto',
    width: 500,
    zIndex:3999,
    modal: false,
    open: function(event, ui) {
        $(event.target).parent().css('position','fixed');
        $(event.target).parent().css('top', '5px');
        $(event.target).parent().css('left', '10px');
    }

});

```

Answer: 
How about wrapping all this with

```
if(window==window.top) {
   // we're not in an iframe
   // your code goes here
}

```
As PAEz said in a comment, content scripts run in only the top frame by default. To make them run in subframes, you'd need to have '"all\_frames":true' in the [content\_scripts section of your manifest](https://developer.chrome.com/extensions/content_scripts.html). Similarly, if you're injecting script using [tabs.executeScript](https://developer.chrome.com/extensions/tabs.html#method-executeScript), you'd have to include '"allFrames":true' in the [InjectDetails](https://developer.chrome.com/extensions/tabs.html#type-InjectDetails) argument.