使用Notifation显示桌面通知
2017-06-11 19:57
218 查看
使用Chrome的时候有时我们会收到这样的提示:
之后就可能在右下角弹出类似提示框一样的通知,但是与普通的提示框比如jquery-ui实现的不同的是,这个提示框不属于DOM元素,而是属于桌面系统的元素,不依赖与浏览器的位置,大小,开关而存在。
我们可以在最开始请求Notifation的权限:
然后创建一个通知实例
效果:
API参考:https://developer.mozilla.org/zh-CN/docs/Web/API/notification
兼容性:http://caniuse.com/#feat=notifications 不支持IE
之后就可能在右下角弹出类似提示框一样的通知,但是与普通的提示框比如jquery-ui实现的不同的是,这个提示框不属于DOM元素,而是属于桌面系统的元素,不依赖与浏览器的位置,大小,开关而存在。
我们可以在最开始请求Notifation的权限:
if (window.Notification && Notification.permission !== "granted") { Notification.requestPermission(function (status) { if (Notification.permission !== status) { Notification.permission = status; } }); }
然后创建一个通知实例
//第二个参数可选,其中icon为左侧图片的url, body为通知的内容 var options = { icon: "./pic.jpg", body: "hello, a demo of notifation" } //第一个参数为通知标题 var n = new Notification("The title!", options);
效果:
API参考:https://developer.mozilla.org/zh-CN/docs/Web/API/notification
兼容性:http://caniuse.com/#feat=notifications 不支持IE
相关文章推荐
- 如何使用通知列表只显示标题
- Windows 7使用宝典安装技巧篇(7)——如何在Win7桌面上显示“我的电脑”
- Android--使用Notification在通知栏显示消息
- SharePoint2010:使用通知和状态栏区域动态显示信息
- SharePoint2010:使用通知和状态栏区域动态显示信息
- 关于使用Intel集成显示芯片桌面右键迟钝问题的解决办法
- Broadcast使用以及在通知栏显示消息
- C#使用系统的“显示桌面”功能(Shell.Application)
- 使用Notification通知来显示接收的短信内容
- Mac使用技巧之快速显示桌面
- Windows 7使用宝典安装技巧篇之——如何在Win7桌面上显示“我的电脑”
- 通知栏Notification使用自定义视图方法(显示一个进度条ProgressBar)
- 如何在windows上使用putty来显示远端linux的桌面
- 苹果新手Mac OS X 使用笔记--------显示桌面,切换程序
- android应用程序,使用不同方法,在activity之中隐藏Title,或者实现FullScreen(隐藏通知栏)显示。
- C#使用系统的“显示桌面”功能(Shell.Application)
- Win7下使用双屏 显示不同分辨率的桌面
- [给力原创]使用jQuery-ajax仿新浪微博通知折叠/显示效果,实现数据加载(二)
- 使用自定义端点创建一个巴斯启用桌面应用程序发送通知到您的移动应用程序
- Chrome浏览器桌面通知提示功能使用