Chrome ext, content script that creates jQuery dialog should ignore iframes

I have a simple chrome extension that opens a jQuery dialog on every open tab,
the problem is that the web page has an iframe in it, the dialog box opens because there are so many frames on the page.
I want to avoid this, all I need is to open it, and only 1 instance of the dialog box for each page. how can i avoid iframes on 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'); } }); 
0
source share
2 answers

How to wrap it all with

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

As PAEz commented, content scripts work by default only in the top frame. To make them work in subframes, you need to have "all_frames": true "in the content_scripts section of your manifest . Similarly, if you enter a script using tabs.executeScript , you will need to include" "allFrames": true 'in InjectDetails .

0
source

All Articles