1

タブが更新されているときに、Googleページにiframeを追加しようとしています。iframe には、更新された URL とタイトルが表示されます。プログラム的には、iframe が挿入されていることを示していますが、ページに iframe が表示されません。以下は、コンテンツ スクリプトのコードです。

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { //onUpdated should fire when the selected tab is changed or a link is clicked 
  if (changeInfo.status == "complete") {
    chrome.tabs.getSelected(null, function (tab) {
        if (tab.url.indexOf(".google.") != -1) {
            url = getRetailer(tab.url);
            title = tab.title;
            title = tab.title.replace(" - Google Search", "");
            createiframe(url, title);
        }

    });
  }
});

function createIframe(url, PN, uid) {
   var iframe = document.createElement("iframe");
   var div = document.createElement("div");
   iframe.src = "url:" + url + 'title:" + PN ;
   iframe.setAttribute("id", "cr_Iframe");
   iframe.setAttribute("style", "position: fixed; z-index: 100001; left: 0pt; right: 0pt; top: 0pt; width: 100%; height: 42px; display: block;");
   iframe.setAttribute("scrolling", "no");
   iframe.setAttribute("frameborder", "0");
   iframe.setAttribute("name", "cr_Iframe");
   document.body.insertBefore(iframe, document.body.firstChild);
}
4

1 に答える 1

2

拡張機能の背景ページやポップアップ ページなどの内部に iframe を作成しています。chrome.tabs.executeScript()マニフェストを介して、または直接介して、コード全体をコンテンツ スクリプトに渡す必要があります。

"content_scripts": [
   {
     "matches": ["*://*.google.*"],
     "js": ["body_of_createIframe_function.js"]
   }
 ],
于 2012-06-15T06:30:17.197 に答える