[TOC] [https://electronjs.org/docs/api/web-contents](https://electronjs.org/docs/api/web-contents) ## 方法 ``` const { webContents } = require('electron') console.log(webContents) ``` ### webContents.getAllWebContents() 返回 所有 WebContents 实例的数组 ### webContents.getFocusedWebContents() 聚焦的webcontents ### webContents.fromId(id) ## 实例事件 ### Event: 'did-frame-finish-load' 当框架完成导航(navigation)时触发 ### Event: 'devtools-opened' 当开发者工具被打开时,触发该事件。 ## 实例方法 ### loadURL(url[, options]) ``` const { webContents } = require('electron') const options = { extraHeaders: 'pragma: no-cache\n' } webContents.loadURL('https://github.com', options) ``` ### loadFile(filePath[, options]) `win.loadFile('src/index.html') ` ### downloadURL(url) ### getURL() ``` const { BrowserWindow } = require('electron') let win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('http://github.com') let currentURL = win.webContents.getURL() console.log(currentURL) ``` ### getTitle() ### isDestroyed() 页面是否销毁 ### isLoading() 判断是否正在加载页面 ### stop() ### reload() ### reloadIgnoringCache() 忽略缓存强制刷新页面 ### goBack() /goForward()