0

我有一个简单的 chrome 扩展,可以在我打开的每个选项卡上打开 JQuery 对话框,
问题是当网页中有 iframe 时,对话框打开页面中的 iframe 数量。
我想避免这种情况,我只需要打开它,并且每个页面只有 1 个对话框实例。如何避免页面中的 iframe?
这是我的内容脚本:

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');
    }

});
4

2 回答 2

2

把这一切都包起来怎么样

if(window==window.top) {
   // we're not in an iframe
   // your code goes here
}
于 2012-12-06T09:59:19.010 回答
0

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. Similarly, if you're injecting script using tabs.executeScript, you'd have to include '"allFrames":true' in the InjectDetails argument.

于 2012-12-07T00:55:32.853 回答