Merge pull request #2650 from deepak1556/webcontents_download_event_patch

app: add will-download event to defaultSession
This commit is contained in:
Cheng Zhao 2015-09-01 20:10:43 +08:00
commit 4e7f56846f
6 changed files with 104 additions and 3 deletions

View file

@ -13,6 +13,30 @@ win.loadUrl("http://github.com");
var session = win.webContents.session
```
## Events
### Event: 'will-download'
* `event` Event
* `downloadItem` Object
* `url` String
* `filename` String
* `mimeType` String
* `hasUserGesture` Boolean
* `webContents` (WebContents)[web-contents.md]
Fired when a download is about to start. Calling `preventDefault()`
will cancel the download.
```javascript
session.on('will-download', function(e, downloadItem, webContents) {
e.preventDefault();
require('request')(downloadItem.url, function(data) {
require('fs').writeFileSync('/somewhere', data);
});
});
```
## Methods
The `session` object has the following methods: