HTML5的Notifycations怎么应用-成都快上网建站

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> URL分享:<a href="http://kswjz.com/article/gdcdsp.html">http://kswjz.com/article/gdcdsp.html</a> </div> <div class="view-qrocde cl"> <div class="m z"><img src="/Public/Home/images/ew.jpg"/></div> <div class="text"> <h6>扫二维码与项目经理沟通</h6> <p>我们在微信上24小时期待你的声音</p> <p>解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流</p> </div> </div> <div class="othernews cl"> <h3>其他资讯</h3> <ul> <li><a href="/article/deipeje.html">Java撤销代码 java删除的代码</a></li><li><a href="/article/deipeih.html">路由器无线设置mac地址 路由器设置mac地址是什么意思</a></li><li><a href="/article/deipesh.html">vim编写java代码 vim debug java</a></li><li><a href="/article/deipees.html">100元的路由器 100元路由器哪个牌子好</a></li><li><a href="/article/deipsph.html">阿里云服务器r如何改操作系统 阿里云服务器怎么更换系统</a></li> </ul> </div> </div> </div> <div class="sidebar"> <div class="tuijian"> <a href="#"> <h2 class="cl"><span>行业动态</span></h2> <h3>企业网站建设的重要性!</h3> <p>现在虽然是移动互联网时代,但企业网站依然重要,包含PC站点,移动站。可以说企业网站关系企业的未来发展和前途,尤其对中小企业更是如此,一些中小企业老板,对自己的名片很在乎,因为这是个门面。...</p> </a> </div> <div class="ser sidesub"> <h2>服务项目</h2> <ul class="ebox"> <li class="sub sub-1"> <div> <h3>网站建设</h3> <p></p> <a class="btn" href="/serve/website/">查看详情</a> </div> </li> <li class="sub sub-1"> <div> <h3>移动端/APP</h3> <p></p> <a class="btn" href="/serve/moblie/">查看详情</a> </div> </li> <li class="sub sub-1"> <div> <h3>微信/小程序</h3> <p></p> <a class="btn" href="/serve/small/">查看详情</a> </div> </li> <li class="sub sub-1"> <div> <h3>技术支持</h3> <p></p> <a class="btn" href="/serve/tech/">查看详情</a> </div> </li> <li class="sub sub-1"> <div> <h3>其它服务</h3> <p></p> <a class="btn" href="/serve/othe/">查看详情</a> </div> </li> <li class="sub sub-5"> <div> <h3>更多服务项目</h3> <p> <a>用我们的专业和诚信赢得您的信赖,从PC到移动互联网均有您想要的服务!</a></p> <a class="btn" href="/serve/">获取更多</a> </div> </li> </ul> </div> <div class="contact" id="fix"> <h2 class="cl"> <span>联系吧</span> <a href="https://map.baidu.com/" class="ditu" rel="nofollow" target="_blank">在百度地图上找到我们</a> </h2> <h3>电话:13518219792</h3> <p>如遇占线或暂未接听请拨:136xxx98888</p> <div class="qq"> <a href="//wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes" rel="nofollow" target="_blank">业务咨询</a> <a href="//wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes" rel="nofollow" target="_blank">技术咨询</a> <a href="//wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes" rel="nofollow" target="_blank">售后服务</a> </div> </div> </div> <script> //固定滚动 (function () { var oDiv = document.getElementById("fix"); var H = 120, iE6; var Y = oDiv; while (Y) { H += Y.offsetTop; Y = Y.offsetParent }; iE6 = window.ActiveXObject && !window.XMLHttpRequest; if (!iE6) { window.onscroll = function () { var s = document.body.scrollTop || document.documentElement.scrollTop; if (s > H) { oDiv.className = "contact fixed"; if (iE6) { oDiv.style.top = (s - H) + "px"; } } else { oDiv.className = "contact "; } }; } })(); </script> </div> <div class="footer"> <div class="wp"> <div class="wpss cl"> <dl class="about"> <dt>网站设计</dt> <dd><a href="http://www.cdxwcx.cn/" target="_blank" title="成都网站设计">成都网站设计</a></dd><dd><a href="http://seo.cdkjz.cn/mobile/" target="_blank" title="自适应网站设计">自适应网站设计</a></dd><dd><a href="http://www.abwzjs.com/" target="_blank" title="阿坝网站设计">阿坝网站设计</a></dd><dd><a href="http://chengdu.cdcxhl.cn/qiye/" target="_blank" title="企业网站设计">企业网站设计</a></dd> </dl> <dl class="about"> <dt>网站制作</dt> <dd><a href="http://www.36103.cn/" target="_blank" title="成都网站制作">成都网站制作</a></dd><dd><a href="http://chengdu.cdxwcx.cn/" target="_blank" title="成都网站制作">成都网站制作</a></dd><dd><a href="http://www.cqcxhl.com/" target="_blank" title="网站制作">网站制作</a></dd><dd><a href="http://www.cxjianzhan.com/" target="_blank" title="网站制作">网站制作</a></dd> </dl> <dl class="contact"> <dt>联系我们</dt> <dd>电话:13518219792</dd> <dd>邮箱:631063699@qq.com</dd> <dd>地址:成都青羊区锦天国际1002号</dd> <dd>网址:www.kswjz.com</dd> </dl> <dl class="about" style="margin-left:50px;width:235px;"> <dt>网站建设</dt> <dd><a href="https://www.cdxwcx.com/wangzhan/pinpai.html" target="_blank" title="高端品牌网站建设">高端品牌网站建设</a></dd><dd><a href="https://www.cdxwcx.com/city/meishan/" target="_blank" title="眉山网站建设">眉山网站建设</a></dd><dd><a href="http://www.cdkjz.cn/fangan/xuexiao/" target="_blank" title="校园网站建设方案">校园网站建设方案</a></dd><dd><a href="http://chengdu.cdcxhl.cn/jianshe/" target="_blank" title="网站建设公司">网站建设公司</a></dd> </dl> <dl class="flow"> <dt></dt> <div class="ma cl"> <div class="m"> <img src="/Public/Home/images/ew.jpg" /> <p>微信二维码</p> </div> </div> </dl> </div> </div> <div class="footer-link wp"> <ul class="wpss cl"> <li class="fisrt">友情链接</li> <li><a href="http://www.bgwzsj.com/" title="班戈纳美网站" target="_blank">班戈纳美网站</a></li><li><a href="http://www.gzzbrs.cn/" title="甘孜州博瑞斯" target="_blank">甘孜州博瑞斯</a></li><li><a href="http://www.nzjike.com/" title="一带一路" target="_blank">一带一路</a></li><li><a href="https://www.scvps.cn/" title="申请域名" target="_blank">申请域名</a></li><li><a href="http://www.cdhuace.com/logo.html" title="标志设计" target="_blank">标志设计</a></li><li><a href="http://www.cxjianzhan.com/baojia/" title="网站建设策划方案" target="_blank">网站建设策划方案</a></li><li><a href="https://www.xwcx.net/jigui.html" title="成都服务器机柜租用" target="_blank">成都服务器机柜租用</a></li><li><a href="http://mc.scmwjz.com/" title="成都封阳台" target="_blank">成都封阳台</a></li><li><a href="http://www.gzjike.cn/" title="公路钻孔机" target="_blank">公路钻孔机</a></li><li><a href="https://www.cdcxhl.com/idc/cqwld.html" title="重庆电信五里店机房" target="_blank">重庆电信五里店机房</a></li> </ul> </div> </div> <div class="bot-footer"> <div class="wp"> <p class="wpss"> <em>Copyright © 2002-2023 www.kswjz.com 快上网建站品牌 QQ:244261566 版权所有</em> <em>备案号:<a href="http://beian.miit.gov.cn/" rel="external nofollow">蜀ICP备19037934号</a></em> </p> <p class="wpss" style="line-height:30px !important;"> </p> </div> </div> <div class="footer-kefu"> <ul> <li class="qq"><a href="https://wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes"><em></em>在线咨询</a> </li> <li class="tel"><a href="tel:13518219792" target="_blank"><em></em>13518219792</a></li> <li class="wx"> <em></em> <div class="code"> <img src="/Public/Home/images/ew.jpg" /> <p>微信二维码</p> </div> </li> <li class="m"> <em></em> <div class="code"> <img src="/Public/Home/images/ew.jpg" /> <p>移动版官网</p> </div> </li> <li class="top"><em></em></li> </ul> </div> <script src="/Public/Home/js/all.js"></script> </body> </html> <script> $(".cont 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>