用Jquery 写一个简单的消息提醒(带声音提示)
2017-06-07 14:19
1056 查看
上周在公司做的一个Web聊天程序,需要一个即时消息提醒并且带有声音提示的功能,在网上找了一下资料,Jquery有个一插件 Jquery.Notify 这个运用比较
广,官网有他的详细介绍(https://notifyjs.com/)我这边只是依据我的需求简单的运用了一下;对了!他还有相应的Bootstrap封装的版本,功能似乎更加强大
(http://bootstrap-notify.remabledesigns.com/),不多说了,先贴一下我的代码,有问题的地方还请提出:
广,官网有他的详细介绍(https://notifyjs.com/)我这边只是依据我的需求简单的运用了一下;对了!他还有相应的Bootstrap封装的版本,功能似乎更加强大
(http://bootstrap-notify.remabledesigns.com/),不多说了,先贴一下我的代码,有问题的地方还请提出:
$(function(){ var receiveIcon; var receiveMessage; var audioElementHovertree; var showNotification =false; //只在当前页面失去焦点时提示消息 window.onblur = function () { showNotification = true; } window.onfocus = function () { showNotification = false; }}); //消息提醒 function check() { // Let's check if the browser supports notifications if (!("Notification" in window)) { //alert("This browser does not support desktop notification"); return false; } if (Notification.permission !== "granted") { Notification.requestPermission(function (permission) { // Whatever the user answers, we make sure we store the information if (!('permission' in Notification)) { Notification.permission = permission; } }); return false; } return showNotification; } function notifyMe() { if (check()) { var notification = new Notification('新的消息', { icon: receiveIcon, //body: "Hey there! You've been notified!", body:receiveMessage }); notification.onshow = function () { $('audio').remove(); audioElementHovertree = document.createElement('audio'); audioElementHovertree.setAttribute('src', 'http://w.qq.com/audio/classic.mp3'); audioElementHovertree.setAttribute('autoplay', 'autoplay'); //打开自动播放 //audioElement.load(); } notification.onclick = function () { window.focus(); }; setTimeout(notification.close.bind(notification), 5000);//auto clear notifications } }
相关文章推荐
- 一个简单的消息提示jquery插件
- 分享一个基于jQuery,backbone.js和underscore.js的消息提示框架 - Backbone.Notifier
- 分享一个基于jQuery,backbone.js和underscore.js的消息提示框架 - Backbone.Notifier
- JQuery实现一个简单的鼠标跟随提示效果
- 一个超棒的消息提示jQuery插件 - Noty
- 消息提醒、带声音提示、托盘图标闪烁
- jquery谢了一个简单的屏幕锁定提示框
- JQuery实现一个简单的鼠标跟随提示效果
- 一个超棒的消息提示jQuery插件 - Noty
- 一个简单的顶部菜单消息提醒功能
- 自己写的一个简单的jQuery提示插件
- 做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法。 很方便的,于是就简单的整理了一下。 1.1 showMessageDialog 显示一个带有OK 按钮的模态
- 基于JQuery的一个简单的鼠标跟随提示效果
- jquery提示消息,简单通用
- 项目中用到的一个小插件,基于jQuery的消息提醒 toastr.js
- jQuery实现类似微博定时刷新提示新消息的功能及有声音提示
- 分享一个基于jQuery,backbone.js和underscore.js的消息提示框架 -...
- 一个超棒的消息提示jQuery插件 - Noty
- 一个简单的基于jquery的表单输入提示案例
- jquery做的一个简单的屏幕锁定提示框