Reputation: 241
I have been trying to add the iframe in the google page when the tab is being updated. The iframe shows the updated url and the title. Programmtically it shows that that the iframe has been inserted but i cannot see the iframe on the page. Following is the code in my content script:
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);
}
Upvotes: 1
Views: 606
Reputation: 10907
You're creating the iframe inside your extension background page or pop-up page or whatever. You'll need to pass the whole code to a content script, either via chrome.tabs.executeScript()
or directly via manifest:
"content_scripts": [
{
"matches": ["*://*.google.*"],
"js": ["body_of_createIframe_function.js"]
}
],
Upvotes: 2