废话不多说,直接上代码
function createNotify(title, options) { var PERMISSON_GRANTED = 'granted'; var PERMISSON_DENIED = 'denied'; var PERMISSON_DEFAULT = 'default'; if (Notification.permission === PERMISSON_GRANTED) { notify(title, options); } else { Notification.requestPermission(function (res) { if (res === PERMISSON_GRANTED) { notify(title, options); } }); } function notify($title, $options) { var notification = new Notification($title, $options); } } createNotify('通知标题', { body: '通知正文' });
微信扫码查看本文
发表评论