/ / Click event on Google Notification - google-chrome, google-chrome-extension

Kliknite na udalosť v Google Notification - google-chrome, google-chrome-extension

Vyvíjam rozšírenie google chrome pre svoj web.

Chcem, aby sa môj web otvoril, keď používateľ klikne na upozornenie google chrome na pracovnej ploche.

Ako teda môžem vyriešiť udalosť kliknutia na upozornenie google chrome na plochu?

odpovede:

-3 pre odpoveď č. 1

Na základe toho: http://code.google.com/chrome/extensions/notifications.html Vyriešil som takto:

Vytvoril som súbor notification.html:

<html>
<head>
<base target="_blank" />
</head>
<body>
<a href="http://example.com">Open site</a>
</body>
</html>

A otvorím upozornenie s týmto kódom:

var notification = webkitNotifications.createHTMLNotification(
"notification.html"
);

notification.show();

Môžete CSS vyzerať ako úplný odkaz bez textu v tele upozornenia.


4 pre odpoveď č. 2

Ak nechcete používať upozornenie HTML, môžete k oznámeniu pridať obslužnú rutinu udalosti kliknutia a zavolať funkciu „zrušiť“.

var notification = window.webkitNotifications.createNotification(
"url", "title", "text");

notification.addEventListener("click", function() {
notification.cancel();
window.open("url")
})
notification.show();