HTML5桌面通知提示功能的实现


本文摘自PHP中文网,作者小云云,侵删。

HTML5赋予网页更好的意义和结构。更加丰富的标签将随着对RDFa的,微数据与微格式等方面的支持,构建对程序、对用户都更有价值的数据驱动的Web。本文我们就和大家分享HTML5实现桌面通知提示功能。

具体代码如下所示:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

<button id="button">有人想加你为好友</button>

<p id="text"></p>

;(function (){

    if(window.Notification){

        var btn = document.getElementById("button");

        var txt = document.getElementById("text");

        btn.onclick = function (){

            if(Notification.permission == "granted"){

                popNotice();

            }else if(Notification.permission != "denied"){

                Notification.requestPermission().then(function (permission){

                    popNotice()

                })

            }

        };

        function popNotice(){

            if(Notification.permission == "granted"){

                var notification = new Notification("你好:",{

                    body:"请问今晚有空吗",

                    icon:"http://image.zhangxinxu.com/左边头像地址"

                });

                notification.onclick = function (){

                    txt.innerHTML = new Date().toTimeString().split(" ")[0]+"收到信息";

                    notification.close();

                }

            }

        }

    }else{

        console.log("浏览器不支持Notification");

    }

})();


阅读剩余部分

相关阅读 >>

h5移动端各种各样的列表的制作方法详解(四)

HTML5 解决苹果手机不能自动播放音乐问题的相关技巧

h5表单介绍和表单验证失败问题实例

HTML5实现文字轮滚的示例代码

制作动态视觉差背景(h5)的方法

url完整结构以及同源跨域处理的介绍

HTML5 canvas来绘制三角形和矩形等多边形的方法

HTML5中当鼠标滚轮正在被滚动时运行的脚本的事件onmousewheel

分享HTML5虚拟键盘出现挡住输入框的解决办法

详细介绍h5中的history.pushstate()使用实例

更多相关阅读请进入《HTML5》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...