docs: Simplify loading of html in example (#13013)
* Simplify loading of html See new api: https://github.com/electron/electron/pull/11565 * Update first-app.md * Update first-app.md
This commit is contained in:
parent
265aa3da29
commit
86fcdd0bae
1 changed files with 2 additions and 14 deletions
|
@ -106,19 +106,13 @@ for the application to be ready and open a window:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {app, BrowserWindow} = require('electron')
|
const {app, BrowserWindow} = require('electron')
|
||||||
const path = require('path')
|
|
||||||
const url = require('url')
|
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow () {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
win = new BrowserWindow({width: 800, height: 600})
|
win = new BrowserWindow({width: 800, height: 600})
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
win.loadURL(url.format({
|
win.loadFile('index.html')
|
||||||
pathname: path.join(__dirname, 'index.html'),
|
|
||||||
protocol: 'file:',
|
|
||||||
slashes: true
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.on('ready', createWindow)
|
app.on('ready', createWindow)
|
||||||
|
@ -131,8 +125,6 @@ windows on macOS if the user clicks on the app's icon in the dock.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {app, BrowserWindow} = require('electron')
|
const {app, BrowserWindow} = require('electron')
|
||||||
const path = require('path')
|
|
||||||
const url = require('url')
|
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
|
@ -143,11 +135,7 @@ function createWindow () {
|
||||||
win = new BrowserWindow({width: 800, height: 600})
|
win = new BrowserWindow({width: 800, height: 600})
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
win.loadURL(url.format({
|
win.loadFile('index.html')
|
||||||
pathname: path.join(__dirname, 'index.html'),
|
|
||||||
protocol: 'file:',
|
|
||||||
slashes: true
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
win.webContents.openDevTools()
|
win.webContents.openDevTools()
|
||||||
|
|
Loading…
Reference in a new issue