1. New/older versions of Chrome and Firefox are supported, so settings are not supported in IE to blink the hint text at minimized windows.
2. Set the prompt window to show 5 seconds to close.
3. You can set the icon and click on the prompt window to jump to the page (see Input parameters).
varTimer =NULL, title= $ (' title '). text (); $(' body '). On (' click ',function() {clearinterval (timer); $(' Title '). Text (title); }); functionshowmsgnotification (title, MSG, ICONURL, Clickurl) {varNotification = window. Notification | | window.moznotification | |window.webkitnotification; if(window.webkitnotifications) {//Chrome old version if(window.webkitNotifications.checkPermission () = = 0) { varNotif =window.webkitNotifications.createNotification (ICONURL, title, MSG); Notif.display=function() {setTimeout (function() {notif.close (); }, 5000); } notif.onerror=function() {} Notif.onclose=function() {} Notif.onclick=function() {window.focus (); Window.location.href=Clickurl; } Notif.replaceid= ' meteoric '; Notif.show (); } Else{window.webkitNotifications.requestPermission ($jy. notify); } } Else if(Notification) {//Support Desktop Notifications if(Notification.permission = = "Granted") {//notification has been allowed varInstance =NewNotification (title, {body:msg, Icon:iconurl //renotify:true }); Instance.onclick=function() { //$ (' body '). CSS ({' Background ': ' Red '}); //console.log (' onclick ');Window.focus (); Window.location.href=Clickurl; //window.open (Clickurl, "_blank"); }; Instance.onerror=function() { //console.log (' onerror '); }; Instance.onshow=function() {setTimeout (function() {instance.close (); }, 5000); }; Instance.onclose=function() { //console.log (' OnClose '); }; }Else{//The first time you ask or have forbidden the notification (if the user has previously suppressed the notification, then the browser will not ask the user again, the Notification.requestpermission () method is invalid)Notification.requestpermission (function(status) {if(Status = = = "Granted") {//user allows varInstance =NewNotification (title, {body:msg, Icon:icon URL}); Instance.onclick=function() {window.focus (); Window.location.href=Clickurl; }; Instance.onerror=function() { //Something to do }; Instance.onshow=function() { //Something to do }; Instance.onclose=function() { //Something to do }; }Else{//User Forbidden return false; } }); } }Else{//not supported (ie, etc.) varindex = 0; Clearinterval (timer); Timer= SetInterval (function() { if(index%2) { $(' title '). Text (' "" ' + title ');//here is the Chinese full-width space, other not}Else { $(' title '). Text (' "flash" ' +title); } Index++; if(Index > 20) {clearinterval (timer); } }, 500); } }
JavaScript compatible with new and legacy Chrome and Firefox desktop notifications