首頁 > web前端 > H5教程 > 什麼是Notifications? HTML5 Notifications桌面提醒

什麼是Notifications? HTML5 Notifications桌面提醒

零下一度
發布: 2017-04-26 16:16:27
原創
2560 人瀏覽過

Notifications是HTML5的一個新特性~ 可以看看360電腦搶票,也是用Notifications提示的~,下面小編寫了一個HTML5 Notifications桌面提醒,還是挺不錯的哦!

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(&#39;浏览器支持Notifications&#39;);

    } else {

        alert(&#39;浏览器不支持Notifications&#39;);

    }

}

 

//请求桌面通知权限

function requestPermission() {

    window.webkitNotifications.requestPermission();

}

 

//获取请求权限状态

function checkPermission() {

    switch (window.webkitNotifications.checkPermission()) {

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

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

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

    }

}

 

//创建文本消息

function textMsg(){

    var icon = &#39;logo.png&#39;;

    var title = &#39;阿鹏\&#39;s BLOG&#39;;

    var body =  &#39;http://www.1990c.com&#39;;

    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(&#39;msg.html&#39;);

 

    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桌面提醒的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
HTML與HTML5的差別
來自於 1970-01-01 08:00:00
0
0
0
symfony 2.1 的 html5 校驗
來自於 1970-01-01 08:00:00
0
0
0
能不能用html5做一個圖片滾動效果
來自於 1970-01-01 08:00:00
0
0
0
想諮詢PHP裡面怎麼寫HTML5
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板