我目前正在工作一個Chrome擴展,它將通知如果getElementId不在頁面中......並且不幸的是豐富的通知未在內容腳本中顯示。我應該使用Message Passing嗎?豐富的通知不工作
load.js
con = document.getElementById('content');
if (con !=null){
var options = {
type:"basic",
title:"Error",
message:"Error",
iconUrl:"logo1.png"
}
chrome.notifications.create(options, callback);
function callback()
{
console.log('yey');
}
}
manifest.json的
{
"manifest_version": 2,
"name": "CRM Online Chrome Extension",
"description": "License authentication key for the clients.",
"version": "1.0",
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"content_scripts":[
{
"matches":[ "*://*/*",
"*://*/*"
],
"js":["payload.js","load.js"]
}
],
"browser_action": {
"default_title": "Sample",
"default_icon": "logo1.png",
"default_popup": "popup.html"
},
"permissions": [
"notifications",
"tabs",
"*://*/*",
"*://*/*"
]
// "options_page": "option.html"
}
'chrome.notification' API是不是由內容腳本進行訪問。你應該傳遞一個消息到後臺頁面,後者會調用'chrome.notification'函數。 –
我明白你的想法,但我不知道該怎麼做。因爲這是第一個我將創建一個擴展,所以我不知道如何語法。如果你給出一個示例語法,對你來說可以嗎? – dionell
@dionell,這個問題包含的代碼與[此問題提前5小時提問]中包含的代碼非常相似(http://stackoverflow.com/q/41009764/3773011)。這是一個團體項目嗎?學校任務? – Makyen