什么是Notifications?HTML5 Notifications桌面提醒


本文摘自PHP中文网,作者零下一度,侵删。

Notifications是HTML5的一个新特性~ 可以看看360电脑抢票,也是用Notifications提示的~,下面小编写了一个HTML5 Notifications桌面提醒,还是挺不错的哦!<!DOCTYPE html>

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

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

<html>

<head>

<meta charset="utf-8">

<title>HTML5 - Notifications</title>

<script>

//判断浏览器是否支持Notifications

function supported(){

    if(window.webkitNotifications){

        alert('浏览器支持Notifications');

    } else {

        alert('浏览器不支持Notifications');

    }

}

 

//请求桌面通知权限

function requestPermission() {

    window.webkitNotifications.requestPermission();

}

 

//获取请求权限状态

function checkPermission() {

    switch (window.webkitNotifications.checkPermission()) {

        case 0:alert('用户已允许显示桌面通知');break;

        case 1:alert('用户还没有允许或拒绝显示桌面通知');break;

        case 2:alert('用户已拒绝显示桌面通知');break;

    }

}

 

//创建文本消息

function textMsg(){

    var icon = 'logo.png';

    var title = '阿鹏\'s BLOG';

    var body =  'http://www.1990c.com';

    var popup = window.webkitNotifications.createNotification(icon, title, body);

 

    popup.ondisplay = function(event) {

        setTimeout(function() {

            event.currentTarget.cancel();

        }, 5000);

    }

 

    popup.show();

}

 

//创建HTML消息

function htmlMsg(){

    var popup = window.webkitNotifications.createHTMLNotification('msg.html');

 

    popup.ondisplay = function(event) {

        setTimeout(function() {

            event.currentTarget.cancel();

        }, 5000);

    }

 

    popup.show();

}

</script>

</head>

 

<body>

<input type="button" value="是否支持桌面提醒" onclick="supported();"/>

<input type="button" value="请求权限" onclick="requestPermission();"/>

<input type="button" value="请求权限状态" onclick="checkPermission();"/>

<input type="button" value="显示文本消息" onclick="textMsg();"/>

<input type="button" value="显示HTML消息" onclick="htmlMsg();"/>

</body>

</html>

以上就是什么是Notifications?HTML5 Notifications桌面提醒的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

html5用什么工具开发

html5是什么?html5有什么用?

h5中文件上传下载实例

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

html5标签嵌套规则的详细介绍

详解html5 placeholder属性

详细介绍html5实现3d迷宫的代码案例

css3和h5实现波纹特效实例代码

html5标准学习-编码详解

html5实战-canvas绘制钟表的示例代码分享

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




打赏

取消

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

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

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

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

评论

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