# ipcRenderer
`ipcRenderer` 模塊是一個
[EventEmitter](https://nodejs.org/api/events.html) 類的實例. 它提供了有限的方法,你可以從渲染進程向主進程發送同步或異步消息. 也可以收到主進程的相應.
查看 [ipcMain](ipc-main.md) 代碼例子.
## 消息監聽
`ipcRenderer` 模塊有下列方法來監聽事件:
### `ipcRenderer.on(channel, listener)`
* `channel` String
* `listener` Function
監聽 `channel`, 當有新消息到達,使用 `listener(event, args...)` 調用 `listener` .
### `ipcRenderer.once(channel, listener)`
* `channel` String
* `listener` Function
為這個事件添加一個一次性 `listener` 函數.這個 `listener` 將在下一次有新消息被發送到 `channel` 的時候被請求調用,之后就被刪除了.
### `ipcRenderer.removeListener(channel, listener)`
* `channel` String
* `listener` Function
從指定的 `channel` 中的監聽者數組刪除指定的 `listener` .
### `ipcRenderer.removeAllListeners([channel])`
* `channel` String (optional)
刪除所有的監聽者,或者刪除指定 `channel` 中的全部.
## 發送消息
`ipcRenderer` 模塊有如下方法來發送消息:
### `ipcRenderer.send(channel[, arg1][, arg2][, ...])`
* `channel` String
* `arg` (可選)
通過 `channel` 向主進程發送異步消息,也可以發送任意參數.參數會被JSON序列化,之后就不會包含函數或原型鏈.
主進程通過使用 `ipcMain` 模塊來監聽 `channel`,從而處理消息.
### `ipcRenderer.sendSync(channel[, arg1][, arg2][, ...])`
* `channel` String
* `arg` (可選)
通過 `channel` 向主進程發送同步消息,也可以發送任意參數.參數會被JSON序列化,之后就不會包含函數或原型鏈.
主進程通過使用 `ipcMain` 模塊來監聽 `channel`,從而處理消息,
通過 `event.returnValue` 來響應.
__注意:__ 發送同步消息將會阻塞整個渲染進程,除非你知道你在做什么,否則就永遠不要用它 .
### `ipcRenderer.sendToHost(channel[, arg1][, arg2][, ...])`
* `channel` String
* `arg` (可選)
類似 `ipcRenderer.send` ,但是它的事件將發往 host page 的 `<webview>` 元素,而不是主進程.
- 介紹
- 常見問題
- Electron 常見問題
- 向導
- 支持平臺
- 分發應用
- 提交應用到 Mac App Store
- 打包應用
- 使用 Node 原生模塊
- 主進程調試
- 使用 Selenium 和 WebDriver
- 使用開發人員工具擴展
- 使用 Pepper Flash 插件
- 使用 Widevine CDM 插件
- 教程
- 快速入門
- 桌面環境集成
- 在線/離線事件探測
- API文檔
- 簡介
- 進程對象
- 支持的 Chrome 命令行開關
- 環境變量
- 自定義的 DOM 元素
- File 對象
- &lt;webview&gt; 標簽
- window.open 函數
- 在主進程內可用的模塊
- app
- autoUpdater
- BrowserWindow
- contentTracing
- dialog
- globalShortcut
- ipcMain
- Menu
- MenuItem
- powerMonitor
- powerSaveBlocker
- protocol
- session
- webContents
- Tray
- 在渲染進程(網頁)內可用的模塊
- desktopCapturer
- ipcRenderer
- remote
- webFrame
- 在兩種進程中都可用的模塊
- clipboard
- crashReporter
- nativeImage
- screen
- shell
- 開發
- 代碼規范
- 源碼目錄結構
- 與 NW.js(原 node-webkit)在技術上的差異
- 構建系統概覽
- 構建步驟(OS X)
- 構建步驟(Windows)
- 構建步驟(Linux)
- 在調試中使用 Symbol Server