如何在Electron中将搜索文本发送到FindPage

如何在Electron中将搜索文本发送到FindPage,electron,Electron,我尝试使用。 我在index.js中有代码: const { webContents } = require('electron') webContents.on('found-in-page', (event, result) => { if (result.finalUpdate) webContents.stopFindInPage('clearSelection') }) const requestId = webContents.findInPage('

我尝试使用。 我在index.js中有代码:

  const { webContents } = require('electron')
  webContents.on('found-in-page', (event, result) => {
    if (result.finalUpdate) webContents.stopFindInPage('clearSelection')
  })

  const requestId = webContents.findInPage('api')
  console.log(requestId)
和组件中的代码:

searchText(value){
    this.query = value;
    if (this.query.length > 0) {
        ipcRenderer.send('api', this.query);
    }
}
我在这个例子上写了这段代码。 但功能不起作用。我不明白如何发送要搜索的文本和要搜索的单词


我如何使用findInPage函数?

很抱歉,我对另一个问题的回答不够清楚(那是两年前的事了!我记不太清楚了,但我会试一试)

这是和的文档

以下是我在main.development.js(用于主窗口和ipc通信的全局文件)中的内容:

然后我为CmdorCtrl+F制作了一个ipc侦听器:

ipcRenderer.on('find_request', () => {
  const modalbox = document.getElementById('modalbox');
 if (modalbox.style.display === 'block') {
   modalbox.style.display = 'none';
} else {
  modalbox.style.display = 'block';
 }
});
然后我制作了一个模态搜索框:

const searchBox = (
  <div
    id="modalbox"
    style={{ display: 'none', position: 'fixed', zIndex: 1 }}
  ><input type="text" onChange={Calls.searchPage} />
  </div>);

我希望这足以让您修复它:)

您的回答对我有帮助,谢谢;)但我还有第二个问题。在我的应用程序中,我的应用程序顶部有一个菜单(它的组件
menu.vue
)。当我搜索somethink单词时(在
News.vue
component中),electron也会标记菜单上的单词。你知道如何修复它吗?有两种方法,你可以放弃WebContent.FindPage,自己写(不推荐)。或者,您可以根据本讨论将菜单放在单独的网络视图中:这个答案对我帮助很大!不过我也有一个新问题——做findNext怎么样?希望能够通过按“回车”键或“下一步”按钮导航到下一个匹配文本。。谢谢
const searchBox = (
  <div
    id="modalbox"
    style={{ display: 'none', position: 'fixed', zIndex: 1 }}
  ><input type="text" onChange={Calls.searchPage} />
  </div>);
static searchPage(event) {
  ipcRenderer.send('search-text', event.target.value);
}