ABPCMS.Web/lib/push.js/README.md
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
# Push.js
[](https://travis-ci.org/Nickersoft/push.js) [](https://npmjs.com/package/push.js) [](https://npmjs.com/package/push.js) [](https://coveralls.io/github/Nickersoft/push.js?branch=master) [](https://snyk.io/test/github/nickersoft/push.js)
### What is Push? ###
Push is the fastest way to get up and running with Javascript desktop notifications. A fairly new addition to the
official specification, the Notification API allows modern browsers such as Chrome, Safari, Firefox, and IE 9+ to push
notifications to a user's desktop. Push acts as a cross-browser solution to this API, falling back to use older
implementations if the user's browser does not support the new API.
You can quickly install Push via [npm](http://npmjs.com):
```
npm install push.js --save
```
Or, if you want something a little more lightweight, you can give [Bower](http://bower.io) a try:
```
bower install push.js --save
```
For more information regarding the Push NPM package, [see here](https://www.npmjs.com/package/push.js).
#### Creating Notifications ####
So just how easy is it to create a notification using Push? We can do it in just one line, actually:
```javascript
Push.create('Hello World!')
```
No constructors, just a universal API you can access from anywhere. Push is even compatible with AMD as well:
```javascript
define(['pushjs'], function (Push) {
Push.create('Hello World!');
});
```
If the browser does not have permission to send push notifications, Push will automatically request permission as soon
as create() is called. Simple as that. If you wish to know how many notifications are currently open, simply call:
```javascript
Push.count();
```
#### Closing Notifications ####
When it comes to closing notifications, you have a few options. You can either set a timeout (see "Options"), call
Push's close() method, or pass around the notification's promise object and then call close() directly. Push's close()
method will only work with newer browsers, taking in a notification's unique tag name and closing the first notification
it finds with that tag:
```javascript
Push.create('Hello World!', {
tag: 'foo'
});
// Somewhere later in your code...
后面还有 130 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
