Merge pull request #924 from atom/webview-ipc-message
Add ipc-message event for <webview>
This commit is contained in:
commit
2fc1e2a4e6
8 changed files with 76 additions and 12 deletions
|
@ -20,3 +20,10 @@ the `channel` event of `ipc` module, and returns by setting `event.returnValue`.
|
|||
|
||||
**Note:** Usually developers should never use this API, since sending
|
||||
synchronous message would block the whole web page.
|
||||
|
||||
## ipc.sendToHost(channel[, args...])
|
||||
|
||||
Like `ipc.send` but the message will be sent to the host page instead of the
|
||||
browser process.
|
||||
|
||||
This is mainly used by the page in `<webview>` to communicate with host page.
|
||||
|
|
|
@ -295,7 +295,7 @@ webview.addEventListener('new-window', function(e) {
|
|||
|
||||
### close
|
||||
|
||||
Fired when the guest window attempts to close itself.
|
||||
Fired when the guest page attempts to close itself.
|
||||
|
||||
The following example code navigates the `webview` to `about:blank` when the
|
||||
guest attempts to close itself.
|
||||
|
@ -306,6 +306,33 @@ webview.addEventListener('close', function() {
|
|||
});
|
||||
```
|
||||
|
||||
### ipc-message
|
||||
|
||||
* `channel` String
|
||||
* `args` Array
|
||||
|
||||
Fired when the guest page has sent an asynchronous message to embedder page.
|
||||
|
||||
With `sendToHost` method and `ipc-message` event you can easily communicate
|
||||
between guest page and embedder page:
|
||||
|
||||
```javascript
|
||||
// In embedder page.
|
||||
webview.addEventListener('ipc-message', function(event) {
|
||||
console.log(event.channel);
|
||||
// Prints "pong"
|
||||
});
|
||||
webview.send('ping');
|
||||
```
|
||||
|
||||
```javascript
|
||||
// In guest page.
|
||||
var ipc = require('ipc');
|
||||
ipc.on('ping', function() {
|
||||
ipc.sendToHost('pong');
|
||||
})
|
||||
```
|
||||
|
||||
### crashed
|
||||
|
||||
Fired when the renderer process is crashed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue