Full text search in Electron BrowserWindow

坚强是说给别人听的谎言 提交于 2020-08-19 11:32:29

问题


Does the Electron application framework have built-in text search?

The quick-start application doesn't provide any apparent search functionality (e.g. using Ctrl-F or from the menu options). I would have expected this to be a BrowserWindow option (or an option of its WebContents), but I don't see anything helpful in the docs.


回答1:


Try webContents.findInPage just added in the latest version.




回答2:


I know this is an old thread, but might still be relevant for people out there. Had the same problem, and first fixed by using electron-in-page-search, but this component doesn't work properly with Electron 2 or greater.

Then finally found electron-find resolved my problem. Using with Electron 4.

You just add the component to your project:

npm install electron-find --save

Add a global shortcut in your Electron main process to send an event to the renderer in a ctrl+f:

globalShortcut.register('CommandOrControl+F', () => {
    window.webContents.send('on-find');
});

And then you can add this to your page (the renderer process)

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()
})

Hope that helps.



来源:https://stackoverflow.com/questions/33837760/full-text-search-in-electron-browserwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!