Compatible with Google, Firefox, 360 series browser desktop notifications () useful

Source: Internet
Author: User

Compatible with Google, Firefox, 360 series browser desktop notifications (useful)

This article from the summary work, and reference a large number of network resources. We want friends with the same needs to help.
(partial):
Http://xsk.tehon.org/den/index.php/category/tech/html5-audio-notifications.html
http://ttsvetko.github.io/HTML5-Desktop-Notifications/#
Http://www.cnblogs.com/meteoric_cry/archive/2012/03/31/2426256.html

1. Notification of authorization issues

Turn on desktop notifications to check whether the current browser is supported and authorized, demo sample code such as the following:

    if (! (" Notification "in Window" &&!window.webkitnotifications) {//Do not support  alert ("Unfortunately, your current browser does not support this feature!) \ \ 360, Google, Firefox and other browsers to use this feature ");    }  else if (notification.permission! = undefined && notification.permission! = null) {if (notification.permission! = "granted") {/* Unauthorized (Google, Firefox)  omitted here 300 lines */}    } else if (notification.permission = = NULL | | Notification.permission = = undefined) {if (window.webkitNotifications.checkPermission ()! = 0) {/* Unauthorized (360 series) omit 300 lines here */ }    }else {/* Supported and authorized (omit 300 lines here) */    }

For example, the following:


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvewltaxl1yw5nz3vhbmc=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">


2, Desktop notification call method

The

    Desktop Notification invocation method (Windowsnotify) is as follows:

/* * Desktop notification * Strnewscontent: The content of the notification */function windowsnotify (strnewscontent) {if (! (" Notification "in Window" &&!window.webkitnotifications && Window.webkitNotifications.checkPermission ()! = 0) return;if (notification.permission = = NULL | | Notification.permission = = undefined) windowsNotify360 (strnewscontent); else if (notification.permission = = = "Granted" ) Windowsnotifyffandge (strnewscontent); else if (notification.permission!== ' denied ') { Notification.requestpermission (function (permission) {if (! (') Permission ' in Notification)) Notification.permission = permission;if (Permission = = = "granted") Windowsnotifyffandge ( strnewscontent);});}} Desktop notifications (compatibility) function windowsNotify360 (strnewscontent) {if (window.webkitnotifications && Window.webkitNotifications.checkPermission () = = 0) {var notify = window.webkitNotifications.createNotification ("http ://www.fx678.com/corp/images/aboutus/htw.jpg "," Huitong-News Center ", strnewscontent);//Set the timer revocation mechanism to prevent the notification from being closed for long periods of time notify . ondispLay = function (event) {setTimeout (function () {event.currentTarget.cancel ();}, 10000);};/ /The following is a definition of a click event, similar to other events Notify.onclick = function () {window.focus (); This.cancel ();};/ /eject Notify.show ();} else if (window.webkitnotifications) {window.webkitNotifications.requestPermission (windowsNotify360);}} Desktop notifications (compatible with Firefox, Google) function Windowsnotifyffandge (strnewscontent) {var notification = new Notification (' Huitong-News Center ', {body: Strnewscontent, Icon: "Http://www.fx678.com/corp/images/aboutus/htw.jpg"});//Set the timer revocation mechanism, Prevents the notification from being closed for a long time Notification.ondisplay = function (event) {setTimeout (function () {event.currentTarget.cancel ();}, 10000 );};/ /The following are defined click events. Similarly, you can define other events Notification.onclick = function () {window.focus (); This.cancel ();};}

For example, the following:


The above content is these, if there are good ways to welcome everyone to correct me! Thank you.




Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Compatible with Google, Firefox, 360 series browser desktop notifications () useful

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.