How do I include a link in a Webkit notification?

I am creating a Chrome extension and I am using the Webkit notification API. I need to show the link in the notification, but the problem is that now the HTML Webkit notifications are out of date, so I can only use notifications with a simple message. I mean, a year ago, I could create a Wbkit HTML notification and include the "a" element, but now I canโ€™t.

Is there a way to show the link in a Webkit notification? Thanks.

+1
source share
2 answers

To make the notification of a web whale link, do this (I use jQuery for events only because it is simpler):

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"; }); 
-one
source

Yes, you can show, check this code as a link.

manifest.json

Registered background page and permissions required for notifications

 { "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 Notification Created

 // create a HTML notification: var notification = webkitNotifications.createHTMLNotification( 'notification.html' // html url - can be relative ); // Then show the notification. notification.show(); 

notification.html

Script tag added to avoid CSP

 <html> <head> <script src="notification.js"></script> </head> <body> <a id="click" href="http://www.google.co.in/">Click Me</a> </body> </html> 

notification.js

Just by indicating a notification on click, you can use it to expand any functionality.

 document.addEventListener("DOMContentLoaded", function () { document.getElementById("click").addEventListener("click", function () { console.log("Clicked"); }); }); 

References

+4
source

Source: https://habr.com/ru/post/1500163/


All Articles