这里是一些被经常问到的问题,再提 issue 之前请先看一下这里。
-+ [Electron 常见问题](faq/electron-faq.md) 需要更新
++ [Electron 常见问题](faq/electron-faq.md)
## 向导
## 开发
* [代码规范](development/coding-style.md)
-* [在 C++ 代码中试用 clang格式化工具](development/clang-format.md) 未翻译
+* [在 C++ 代码中使用 clang格式化工具](development/clang-format.md) 未翻译
* [源码目录结构](development/source-code-directory-structure.md)
* [与 NW.js(原 node-webkit)在技术上的差异](development/atom-shell-vs-node-webkit.md)
* [构建系统概览](development/build-system-overview.md)
## 如何在两个网页间共享数据?
-在两个网页(渲染进程)间共享数据最简单的方法是使用浏览器中已经实现的 HTML5 API,比较好的方案是用 [Storage API][storage],
+在两个网页(渲染进程)间共享数据最简单的方法是使用浏览器中已经实现的 HTML5 API,其中比较好的方案是用 [Storage API][storage],
[`localStorage`][local-storage],[`sessionStorage`][session-storage] 或者 [IndexedDB][indexed-db]。
你还可以用 Electron 内的 IPC 机制实现。将数据存在主进程的某个全局变量中,然后在多个渲染进程中使用 `remote` 模块来访问它。
```javascript
// 在第一个页面中
-require('remote').getGlobal('sharedObject').someProperty = 'new value'
+require('electron').remote.getGlobal('sharedObject').someProperty = 'new value'
```
```javascript
// 在第二个页面中
-console.log(require('remote').getGlobal('sharedObject').someProperty)
+console.log(require('electron').remote.getGlobal('sharedObject').someProperty)
```
## 为什么应用的窗口、托盘在一段时间后不见了?
从
```javascript
-app.on('ready', function () {
- var tray = new Tray('/path/to/icon.png')
+const {app, Tray} = require('electron')
+app.on('ready', () => {
+ const tray = new Tray('/path/to/icon.png')
+ tray.setTitle('hello world')
})
```
改为
```javascript
-var tray = null
-app.on('ready', function () {
+const {app, Tray} = require('electron')
+let tray = null
+app.on('ready', () => {
tray = new Tray('/path/to/icon.png')
+ tray.setTitle('hello world')
})
```