HTML5的Notifycations怎么应用

今天小编给大家分享一下HTML5的Notifycations怎么应用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

创新互联长期为数千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为榕城企业提供专业的网站设计制作、网站制作,榕城网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

HTML5中的桌面提醒(网络通知)可以在当前页面窗口上放置一个消息框,这个消息框是跨Tab窗口的,这在用户打开多个tab浏览网页时,提醒比较方便,容易让用户看到。只要是webkit内核支持该功能。

该功能在chrome下需要以http方式打开网页才能

启用。桌面提醒功能由window.webkitNotifications对象实现(webkit内核)

window.webkitNotifications对象没有属性,有四个方法:

1.requestPermission()

该方法用于向用户申请消息提醒权限,如果当前没有开放该权限,浏览器将打开授权界面,用户授权后,在对象内部产生一个状态值(一个0、1或2的整数):

0:表示用户同意消息提醒,只在该状态下可以使用信息提醒功能;

1:表示状态,用户既未拒绝,也未同意;

2:表示用户拒绝消息提醒

2.checkPermission()

这个方法用于获取requestPermission()申请到的权限的状态值。

3.createNotification()

这个方法以纯消息的方式创建提醒消息,它接受三个字符串参数:

iconURL:消息在显示中的图标种植地址,

标题:消息的标题,

body:消息主体文本内容

该方法会返回一个Notification对象,可以针对这个对象做更多的设置。Notification

对象的属性与方法:

复制代码代码如下: 

DIR: “”

的onclick:空

的OnClose:空

ondisplay:功能(事件){

的onerror:空

OnShow中:空

replaceId: “”

标签: “”

__ PR oto__:通知

的addEventListener:功能的addEventListener(){[本地代码]}

取消:函数cancel(){[本机代码]}

close:函数close(){[本机代码]}

构造函数:函数Notification(){[本机代码]}

dispatchEvent:函数dispatchEvent(){[本机代码]}

removeEventListener:函数removeEventListener (){[本机代码]}

show:函数show(){[本机代码]}

__proto__:对象

dir:设置消息的分配方向,可取到“ auto”(自动),“ ltr”(从左到右),“ rtl”(从右到左)。

标签:为消息添加标签名。如果设置此属性,当有新消息提醒时,标签相同的消息只显示在同一个消息框,后一个消息框会替换先前一个,否则出现多个消息提示框,但最大值显示3个消息框,超过3个,后继消息通知会被阻塞。

OnShow中:当消息框显示的时候触发该事件;

的onclick:当点击消息框的时候触发该事件;

OnClose中:当消息关闭的时候触发该事件;

的onerror:当出现错误的时候触发该事件;

方法:

addEventListener && removeEventListener:常规的添加和

删除事件方法;显示:显示消息提醒框;

关闭:关闭消息提醒框;

取消:关闭消息提醒框,和close一样;

4.createHTMLNotification()

该方法与createNotification()不同的是,他以HTML方式创建消息,接受一个参数:HTML文件的URL,该方法同时返回Notification对象。

一个实例:

复制代码代码如下: 

<!DOCTYPE HTML>

HTML5中的通知</ title></p><p></ head></p><p><body></p><p><form></p><p><input id =“ trynotification” type =“ button” value =“发送通知” / ></p><p></ form></p><p><script type =“ text / javascript”></p><p>document.getElementById(“ trynotification”)。onclick = function(){</p><p>notify(Math.random());</p><p>};</p><p>函数notify(tab){</p><p>如果(!window.webkitNotifications){</p><p>返回false;</p><p>}</p><p>varPermission = window.webkitNotifications.checkPermission();</p><p>if(permission!= 0){</p><p>window.webkitNotifications.requestPermission();</p><p>var requestTime = new Date();</p><p>var waitTime = 5000;</p><p>var checkPerMiniSec = 100;</p><p>setTimeout(function(){</p><p>权限= window.webkitNotifications.checkPermission();</p><p>if(permission == 0){</p><p>createNotification(tab);</p><p>}否则if(new Date()-requestTime <waitTime){</p><p>setTimeout(arguments.callee,checkPerMiniSec );</p><p>}</p><p>},checkPerMiniSec);</p><p>}否则if(permission == 0){</p><p>createNotification(tab);</p><p>}</p><p>}</p><p>函数createNotification(tab){</p><p>var showSec = 10000;</p><p>var icon =“ http://tech.baidu.com/resource/img/logo_news_137_46.png”;</p><p>var title =“ [” + new Date()。toLocaleTimeString()+“]在” +(showSec / 1000)+“秒”之后关闭;</p><p>var body =“你好,世界,</p><p>var popup = window.webkitNotifications.createNotification(icon,title,body);</p><p>popup.tag =选项卡;</p><p>popup.ondisplay = function(event){</p><p>setTimeout(function(){</p><p>event.currentTarget.cancel();</p><p>},showSec);</p><p>}</p><p>popup.show();</p><p>}</p><p></ script></p><p></ body></p><p></ html></p><p>以上就是“HTML5的Notifycations怎么应用”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注创新互联行业资讯频道。</p> <br> 网站栏目:HTML5的Notifycations怎么应用 <br> 本文网址:<a href="http://bzwzjz.com/article/gdcdsp.html">http://bzwzjz.com/article/gdcdsp.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/jjocjp.html">上传本地项目到GitHub</a> </li><li> <a href="/article/jjocje.html">Js存储执行上下文的方法</a> </li><li> <a href="/article/jjocdo.html">linux如何查看目录</a> </li><li> <a href="/article/jjocog.html">windows中ofd文件如何转换格式</a> </li><li> <a href="/article/jjocho.html">Dubbo怎么实现SpringCloud服务治理</a> </li> </ul> </div> </div> <div class="footer2"> Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号 <br />友情链接: <a href="http://www.kswsj.cn/" target="_blank">成都网站建设 </a><a href="http://www.cxjianzhan.cn/fwxm/pinpai.html" target="_blank">成都品牌网站设计 </a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">外贸网站建设 </a><a href="http://www.36103.cn/" target="_blank">成都网站设计 </a><a href="https://www.cdcxhl.com/sheji/chengdu.html" target="_blank">四川成都网站设计 </a><a href="http://chengdu.cdxwcx.cn/wangzhan/" target="_blank">手机网站制作 </a><a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">成都定制网站建设 </a><a href="http://www.kswcd.com/mobile/" target="_blank">手机网站建设 </a><a href="http://m.cdcxhl.com/" target="_blank">成都网站制作 </a><a href="http://chengdu.cdcxhl.cn/" target="_blank">成都网站建设 </a><a href="https://www.cdxwcx.com/wangzhan/mbqiye.html" target="_blank">成都企业网站制作 </a><a href="http://www.scyanting.com/" target="_blank">盐亭网站设计 </a><a href="http://chengdu.cdcxhl.cn/" target="_blank">成都网站设计 </a><a href="http://chengdu.cdxwcx.cn/wangzhan/" target="_blank">企业网站设计 </a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都营销网站制作 </a><a href="http://www.cxjianzhan.cn/" target="_blank">成都网站设计 </a><a href="http://www.cdkjz.cn/" target="_blank">网站建设 </a><a href="http://www.cxjianzhan.com/mobile/" target="_blank">手机网站制作 </a><a href="http://www.cxhljz.com/" target="_blank">网站设计制作 </a><a href="http://www.cxjianzhan.cn/fwxm/yingxiao.html" target="_blank">营销型网站建设 </a><a href="https://www.cdxwcx.com/wangzhan/shop.html" target="_blank">成都商城网站制作 </a><a href="http://www.dzwzjz.com/" target="_blank">达州网站设计 </a></div> </body> </html> <script src="/Public/Home/js/wow.min.js"></script> <script> if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) { new WOW().init(); }; </script> <div class="sidebar"> <ul> <li><a href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/right_qq.png" /></a></li> <li><a href="http://wpa.qq.com/msgrd?v=3&uin=1683211881&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/qq.png" /></a></li> <li class="tel"><a href="tel:028-86922220"><img src="/Public/Home/images/right_tel.png" /></a></li> <div class="wx"> <span class="weixin"><img src="/Public/Home/images/weixin.jpg"><br> 微信扫一扫在线咨询</span> </div> <li><a class="fx" href="#hero"><img src="/Public/Home/images/right_up.png" /></a></li> </ul> </div> <script type="text/javascript"> $(function () { $('.sidebar .fx').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); }); }); </script> <script type="text/javascript"> $(document).ready(function () { $("#fancybox-manual-b").click(function () { $.fancybox.open({ href: 'map.html', type: 'iframe', padding: 5 }); }) }); </script> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>