Google chrome extension 如何在Webkit通知中包含链接?
我正在创建一个Chrome扩展,我正在使用Webkit通知API。我需要在通知中显示一个链接,但问题是现在Webkit HTML通知已被弃用,因此我只能使用带有简单消息的通知。我的意思是,一年前我本可以创建一个Wbkit HTML通知并包含“a”元素,但现在我不能Google chrome extension 如何在Webkit通知中包含链接?,google-chrome-extension,html5-notifications,webkit-notifications,Google Chrome Extension,Html5 Notifications,Webkit Notifications,我正在创建一个Chrome扩展,我正在使用Webkit通知API。我需要在通知中显示一个链接,但问题是现在Webkit HTML通知已被弃用,因此我只能使用带有简单消息的通知。我的意思是,一年前我本可以创建一个Wbkit HTML通知并包含“a”元素,但现在我不能 有没有办法在Webkit通知中显示链接?谢谢。是的,您可以显示、检查此代码作为参考 manifest.json 已注册的后台页面和通知所需的权限 { "name": "Notification with Link",
有没有办法在Webkit通知中显示链接?谢谢。是的,您可以显示、检查此代码作为参考 manifest.json 已注册的后台页面和通知所需的权限
{
"name": "Notification with Link",
"description": "http://stackoverflow.com/questions/14731996/how-to-include-a-link-in-a-webkit-notification",
"manifest_version": 2,
"version": "1",
"permissions": [
"notifications"
],
"background": {
"scripts": [
"background.js"
]
}
}
background.js
创建了一个HTML通知
// create a HTML notification:
var notification = webkitNotifications.createHTMLNotification(
'notification.html' // html url - can be relative
);
// Then show the notification.
notification.show();
notification.html
添加脚本标记以避免CSP
<html>
<head>
<script src="notification.js"></script>
</head>
<body>
<a id="click" href="http://www.google.co.in/">Click Me</a>
</body>
</html>
工具书类
谢谢你的回答!但我认为createHTMLNotification不在规范中,因此可能很快就会从Chrome中删除。根据Google+上的一篇帖子,他们正在删除网页的createHTMLNotification,但它仍然允许在扩展中使用。然而,我担心它是否会是永久性的。
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("click").addEventListener("click", function () {
console.log("Clicked");
});
});
var notification = window.webkitNotifications.createNotification(
"http://www.google.com/images/logo.png", // icon url - can be relative
"Google", // notification title
"is the best search engine. Click to find out more" // notification body text
);
// Show the notification, I'm assuming notifications are supported and allowed
notification.show();
jQuery(notification).click(function(){
window.location = "http://www.google.com";
});