我目前正在工作一个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