的manifest.jsonpopup.js何時啓動?
{
"manifest_version": 2,
"name": "YouTellMe",
"description":"FIND AND COMPARE OVER 10.000.000 PRODUCTS AND GET THE BEST PRICES FROM ALL MAJOR INDIAN WEBSHOPS. GET DISCOUNTS TO HAVE THE CHEAPEST PRICE!",
"version":"0.0",
"browser_action":
{
"default_icon":"logoytm.png",
"default_popup": "offers.html",
"badge" : "YTM"
},
"background" :
{
"scripts" : ["find_offers.js"],
"persistent" : false
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"permissions":
[
"tabs",
"activeTab",
"webNavigation",
"notifications",
"https://ajax.googleapis.com/",
"http://localhost/*",
]}
find_offers.js
if(! window.jQuery)
{
\t console.log("importing jquery...")
\t script = document.createElement('script');
\t script.source = 'http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js';
\t document.getElementsByTagName("head")[0].appendChild(script)
}
chrome.tabs.onUpdated.addListener(tab_activated);
chrome.webNavigation.onCompleted.addListener(load_iframe);
var tablink;
function tab_activated()
{
\t chrome.tabs.query({'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT},
function(tabs)
{
\t \t \t tablink = tabs[0].url;
});
}
function load_iframe()
{
\t console.log("in load iframe");
\t ytm_product_url = "http://localhost/bookmarklet/product/";
console.log("current URL " + tablink);
if(tablink != undefined)
{
\t var uri = ytm_product_url+"?retailer_url="+tablink;
}
else
\t {
\t var uri = ytm_product_url+"?retailer_url="+document.location.href;
\t }
chrome.extension.sendMessage({url:uri});
}
offers.html
<html>
<head>
<title></title>
</head>
<link rel="stylesheet" type="text/x-scss" href="bookmark_offers.css" />
<script src='jquery.min.js'></script>
<script src='load_offers.js'> </script>
<body>
<div id="YTM_offers"> </div>
</body>
</html>
load_offers.js
chrome.runtime.onMessage.addListener
(
\t function (request)
{
\t \t alert("message received");
$.ajax
(
{
url : request.url,
}
)
.done
(
function(data)
{
\t notifyUser();
console.log($("#YTM_offers")[0]);
// document.getElementById('YTM_offers').innerHTML += data;
$("#YTM_offers").html(data);
console.log($("#YTM_offers"));
}
)
}
)
function notifyUser()
{
\t console.log("notification...")
\t if (! Notification)
\t {
\t \t alert('Notifications are supported in modern versions of Chrome, Firefox, Opera and Firefox.');
\t return;
\t }
\t
\t if(Notification.permission !== "granted")
\t \t Notification.requestPermission();
\t
\t var notification = new Notification("YouTellMe",
\t \t \t { icon : 'logoytm.png',
\t \t \t \t body : "We've got more offers for you." +
\t \t \t \t \t \t "\nClick on extension Icon for more details."
\t \t \t });
}
現在的問題發言。 我發送當前頁面的網址從find_offers.js
到load_offers.js
,然後load_offers.js
從服務器中提取相關的報價,這是正在填寫名爲YTM_offers
的div。
load_offers.js
正在偵聽來自find_offers.js的消息(url),但這裏的發送部分工作正常,但接收部分不工作,直到我檢查popup.html並重新加載當前頁面。
我做錯了什麼? 幫助thank.Thanks
感謝您的回覆。是的,你正在寫,我知道在閱讀問題標題後。所以現在我想從後臺js中的服務器中獲取數據,並通知用戶數據已準備就緒,點擊數據圖標,因爲popup不能實際打開。 –
所以。做吧!提取數據,如果有用戶的有趣信息 - 使用'browserAction.setBadgeText'或更改圖標以表明您有信息要顯示,並將該信息存儲在'chrome.storage'中。在彈出窗口中,打開時從'chrome.storage'中取出數據。 – Xan
感謝您的想法(chrome.storage) –