zoukankan      html  css  js  c++  java
  • web notification api

    Web Notifications API 使页面可以发出通知,通知将被显示在页面之外的系统层面上(通常使用操作系统的标准通知机制,但是在不同的平台和浏览器上的表现会有差异)

    要显示一条通知,你需要先请求适当的权限。Web Notifications API 请求 权限有两种方式

    1、Notification.requestPermission(callback)      

    2、Notification.requestPermission().then(function(status){  ...  })

    Notification.requestPermission().then(function(status) {
        console.log(status)            //status有三种状态  default默认(会询问用户是否开启通知的权限granted已经允许开启通知    denied用户已经明确的拒绝了显示通知的权限。
      if(status == 'granted'){ 
         
    new Notification(title, { //new Notification是发送通知 title是标题 body是通知的内容 icon发送人的图标
            body:
    'can i addfriend you',
            icon:
    'http://combustion-engines.oss-cn-shanghai.aliyuncs.com/CombustionEnginesTupian/2017/dfbb2d68-97e4-4b9f-8d5f-82a636e3edcc.png'
    }) } });

     详情可以去这里查看MDN web notification api

  • 相关阅读:
    树的直径 学习笔记
    SDOJ 3742 黑白图
    【SDOJ 3741】 【poj2528】 Mayor's posters
    SDOJ 3740 Graph
    SDOJ 3696 Tree
    SDOJ 1195 Zhenhuan
    又一次受刺激后的发奋
    html_表单form中的input类型大集合
    js_表格的增删改
    JS_拖拽窗口的实现
  • 原文地址:https://www.cnblogs.com/guojikun/p/7274678.html
Copyright © 2011-2022 走看看