桌面消息提醒

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box{
width:100%;
height:1000px;
}
.title{
display:none;
width:300px;
height:100px;
border:1px solid red;
position: fixed;
right:0px;
top:10px;
}
.btn{
width:50px;
height:20px;
line-height:20px;
text-align: center;
border:1px solid red;
}
</style>
</head>
<body>
<div class="box">
<div class="btn" id="btn">
弹出
</div>
</div>
<div class="title">
qwertyuiop[]dfghjkghjkhjk
</div>
</body>
<script src="jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
// $('.btn').on('click',function(){
// $('.title').css({
// 'display':'block'
// })
// })
// if (window.Notification)
//{
// if (window.Notification.permission == "granted") {
// var notification = new Notification('标题', {
// body: "内容",
// icon: "图标路径,若不指定默认为favicon"
// });
// } else {
// window.Notification.requestPermission();
// }
//}
cue(1,2,3);
function cue(tel,content,hint){
if (window.Notification) {
var popNotice = function() {
if (Notification.permission == "granted") {
var notification = new Notification(tel, {
body: content,
icon: 'http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg'
});
notification.onclick = function() {
alert(hint);
notification.close();
};
}
};
if (Notification.permission == "granted") {
popNotice();
} else if (Notification.permission != "denied") {
Notification.requestPermission(function (permission) {
popNotice();
});
}
} else {
alert('浏览器不支持Notification');
}
}
//if (window.Notification) {
// var button = document.getElementById('btn'), text = document.getElementById('text');
//
// var popNotice = function() {
// if (Notification.permission == "granted") {
// var notification = new Notification("Hi,帅哥:", {
// body: '可以加你为好友吗?',
// icon: 'http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg',
//// silent:true,
//// sound:'1704.mp3',
//
// });
//// notification.onshow = function () {
//// setTimeout(function(){
//// notification.close()}, 5000);
////
//// }
// notification.onclick = function() {
// alert(123);
// window.onfocus = function() {
// isShine = false;
// };
// notification.close();
// };
// }
// };
//
// button.onclick = function() {
// if (Notification.permission == "granted") {
// popNotice();
// } else if (Notification.permission != "denied") {
// Notification.requestPermission(function (permission) {
// popNotice();
// });
// }
// };
//} else {
// alert('浏览器不支持Notification');
//}

 

fun(true);
var titleInit = document.title;
function fun(temp){
isShine = temp;
setInterval(function() {
var title = document.title;
if (isShine == true) {
if (/新/.test(title) == false) {
document.title = '【你有新消息】';
} else {
document.title = '【     】';
}
} else {
document.title = titleInit;
}
}, 500);

window.onfocus = function() {
isShine = false;
};
window.onclick = function() {
isShine = false;
};
window.onblur = function() {
isShine = '';
};

// for IE
document.onfocusin = function() {
isShine = false;
};
document.onfocusout = function() {
isShine ='';
};
}
</script>
</html>

posted @ 2017-06-12 20:35  missJun  阅读(273)  评论(0编辑  收藏  举报