الإشعارات الغنية باستخدام webKit

استخدم إشعارات سطح المكتب الغنية لإعلام المستخدمين بحدوث حدث مهم. تظهر الإشعارات خارج نافذة المتصفح. كما توضّح اللقطات التالية، تعتمد تفاصيل شكل الإشعارات ومكان ظهورها على النظام الأساسي.

الإشعارات على Microsoft Windows

الإشعارات على Mac OS X

الإشعارات على نظام التشغيل Ubuntu Linux

يمكنك إنشاء نافذة الإشعار باستخدام جزء من JavaScript، واختياريًا صفحة HTML مضمّنة في الإضافة.

مثال

عليك أولاً تعريف الإذن 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. تجاهل الرمز المتعلق بالإذن؛ ليس من الضروري أن تعلن عن إذن "الإشعارات".