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> 分享地址:<a href="http://kswsj.cn/article/gdcdsp.html">http://kswsj.cn/article/gdcdsp.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/pedoio.html">PHP打印格式化的示例</a> </li><li> <a href="/article/pedooh.html">Metrics中怎么监控应用程序的性能</a> </li><li> <a href="/article/pedoei.html">无法引用jquery的解决方法</a> </li><li> <a href="/article/pedoej.html">windows上安装配置redis群集</a> </li><li> <a href="/article/pedosj.html">如何使用vue写一个简书的轮播图</a> </li> </ul> </div> </div> <div class="line"></div> <!--底部--> <footer id="5"> <div class="foot1 container"> <div class="list"> <div class="item"> <a href="javascript:;"> <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span> <strong>关注我们</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>索要报价</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>我要咨询</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>找到我们</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>投诉建议</strong> </a> </div> </div> <div class="tel"> <dl> <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br> <span>也许您需要专业的服务,欢迎来电咨询</span> </dl> <dl> <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br> <span>您的需求,是我们前进的动力</span> </dl> </div> </div> <div class="friend"> <div class="container"> <span class="tit">友情链接:</span> <div class="inner"> <a href="https://www.cdcxhl.com/google.html" target="_blank">谷歌推广公司</a><a href="https://www.cdcxhl.com/tuoguan/dianxin/" target="_blank">绵阳服务器托管</a><a href="https://www.cdcxhl.com/quanwang.html" target="_blank">全网营销推广</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文营销推广</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站建设公司</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站设计</a><a href="https://www.cdcxhl.com/app.html" target="_blank">app软件开发</a><a href="https://www.cdcxhl.com/yunying.html" target="_blank">网站运营</a><a href="https://www.cdcxhl.com/sosuo.html" target="_blank">关键词优化排名</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">响应式网站建设公司</a><a href="https://www.cdcxhl.com/gaofang/" target="_blank">高防服务器</a><a href="https://www.cdcxhl.com/h5.html" target="_blank">成都h5网站建设</a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">营销网站建设</a><a href="https://www.cdcxhl.com/yunying.html" target="_blank">成都网站托管运营</a><a href="https://www.cdcxhl.com/quanwang.html" target="_blank">整合营销推广</a><a href="https://www.cdcxhl.com/link/" target="_blank">友情链接出售</a><a href="https://www.cdcxhl.com/qiye.html" target="_blank">企业网站建设</a><a href="https://www.cdcxhl.com/mobile.html" target="_blank">成都手机网站制作</a> </div> </div> </div> <div class="foot"> <div class="container"> <div class="footNav"> <h3>网站建设</h3> <a href="http://chengdu.cdcxhl.com/dingzhi/" target="_blank">定制网站建设</a><a href="http://chengdu.cdcxhl.cn/qiye/" target="_blank">企业网站建设公司</a><a href="http://www.kswcd.com/service/" target="_blank">上市集团网站建设</a> </div> <div class="footNav"> <h3>服务器托管</h3> <a href="https://www.cdcxhl.com/tuoguan/" target="_blank">IDC机房托管</a><a href="https://www.cdcxhl.com/idc/deyang.html" target="_blank">德阳服务器托管</a><a href="https://www.cdcxhl.com/tuoguan.html" target="_blank">成都服务器托管</a> </div> <div class="footNav"> <h3>网站制作</h3> <a href="http://m.cdcxhl.com/" target="_blank">成都网站制作</a><a href="https://www.cdxwcx.com/wangzhan/mbqiye.html" target="_blank">成都企业网站制作</a><a href="http://m.cdcxhl.cn/mobile/" target="_blank">手机网站制作</a> </div> <div class="footNav"> <h3>企业服务</h3> <a href="https://www.cdcxhl.com/service/shipinxuke.html" target="_blank">食品经营许可证</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文发稿</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站收录</a> </div> <div class="fr ecode"> <div class="fl"> <img src="/Public/Home/img/ewm.jpg"> <p>关注企业微信</p> </div> <div class="fr slogan"> <p class="icon"> <a class="ph" href=""><i class="iconfont"></i></a> <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a> </p> <p> <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、 <a href="">营销型网站建设</a>、<a href="">网站建设</a>、 <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a> </p> </div> </div> </div> <div class="bottom container"> <p class="fl"> 版权所有:成都创新互联科技有限公司 备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a> 服务热线:028-86922220 </p> <p class="fr"> <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>: <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a> </p> </div> </div> </footer> <!--在线咨询--> <div class="fot"> <ul> <li> <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank"> <img src="/Public/Home/img/fot1.png" alt=""> <p>在线咨询</p> </a> </li> <li> <a href="tel:18980820575" target="_blank"> <img src="/Public/Home/img/fot2.png" alt=""> <p>拨打电话</p> </a> </li> </ul> </div> </body> </html> <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>