Electron应用程序框架是否具有内置文本搜索功能?
quick-start application不提供任何明显的搜索功能(例如使用Ctrl-F
或菜单选项)。我原以为这是一个BrowserWindow选项(或其WebContents的选项),但我没有看到任何有用的文档。
尝试在最新版本中添加的webContents.findInPage。
我知道这是一个旧线程,但可能仍然适用于那里的人。有同样的问题,并首先使用electron-in-page-search修复,但此组件无法与Electron 2或更高版本一起正常工作。
然后终于找到electron-find解决了我的问题。与Electron 4一起使用。
您只需将组件添加到项目中:
npm install electron-find --save
在Electron主进程中添加全局快捷方式,以ctrl + f将事件发送到渲染器:
globalShortcut.register('CommandOrControl+F', () => {
window.webContents.send('on-find');
});
然后你可以将它添加到你的页面(渲染器过程)
const remote = require('electron').remote;
const FindInPage = require('electron-find').FindInPage;
let findInPage = new FindInPage(remote.getCurrentWebContents());
ipcRenderer.on('on-find', (e, args) => {
findInPage.openFindWindow()
})
希望有所帮助。