webKit के साथ रिच सूचनाएं

उपयोगकर्ताओं को कुछ महत्वपूर्ण होने की सूचना देने के लिए समृद्ध डेस्कटॉप सूचनाओं का उपयोग करें. सूचनाएं ब्राउज़र विंडो के बाहर दिखती हैं. जैसा कि नीचे दिए गए स्नैपशॉट में दिख रहा है, प्लैटफ़ॉर्म पर यह निर्भर करता है कि सूचनाएं कैसे दिखती हैं और वे कहां दिखती हैं.

Microsoft Windows पर सूचनाएं

Mac OS X पर सूचनाएं

Ubuntu Linux पर सूचनाएं

सूचना विंडो छोटे JavaScript का इस्तेमाल करके और वैकल्पिक तौर पर एक्सटेंशन में पैकेज किया गया एचटीएमएल पेज होता है.

उदाहरण

सबसे पहले, अपने मेनिफ़ेस्ट में notifications अनुमति के बारे में बताएं:

{
  "name": "My extension",
  "manifest_version": 2,
  ...
  "permissions": [
    "notifications"
  ],
  ...
  // Note: Because of bug 134315, you must declare any images you
  // want to use with createNotification() as a web accessible resource.
  "web_accessible_resources": [
    "48.png"
  ],
}

इसके बाद, सूचनाएं बनाने के लिए webkitNotifications ऑब्जेक्ट का इस्तेमाल करें:

// Note: There's no need to call webkitNotifications.checkPermission().
// Extensions that declare the notifications permission are always
// allowed create notifications.

// Create a simple text notification:
var notification = webkitNotifications.createNotification(
  '48.png',  // icon url - can be relative
  'Hello!',  // notification title
  'Lorem ipsum...'  // notification body text
);

// Or create an HTML notification:
var notification = webkitNotifications.createHTMLNotification(
  'notification.html'  // html url - can be relative
);

// Then show the notification.
notification.show();

एपीआई का संदर्भ

डेस्कटॉप नोटिफ़िकेशन के ड्राफ़्ट की खास बातें देखें.

दूसरे विचारों से बातचीत करना

अपने एक्सटेंशन में, सूचना और अन्य व्यू के बीच संपर्क किया जा सकता है. इसके लिए, extension.getBackgroundPage और extension.getViews का इस्तेमाल करें. उदाहरण के लिए:

chrome.extension.getBackgroundPage().doThing();
chrome.extension.getViews({type:"notification"}).forEach(function(win) {
  win.doOtherThing();
});

कुछ और उदाहरण

आपको examples/api/notifications में सूचनाओं को इस्तेमाल करने का आसान उदाहरण मिल सकता है. अन्य उदाहरणों और सोर्स कोड के बारे में जानने के लिए, सैंपल देखें.

html5rocks.com का सूचनाओं का ट्यूटोरियल भी देखें. अनुमति से जुड़े कोड को अनदेखा करें; अगर "सूचना" की अनुमति का एलान किया जाता है, तो यह ज़रूरी नहीं है.