如何将变量从电子 html 文件发送到 javascript 文件?

问题描述 投票:0回答:0

我试图从 html 文档的表单中获取一个数字输入,然后将其发送到 javascript 文档和 console.log。即使在尝试调试和尝试多个版本时,它仍然无法正常工作。

HTML文档:

<form id="searchForm" onsubmit="search(event)" class="nodrag">
            <input type="text" id="searchBar" placeholder="COMING SOON">
            <input type="submit" value="O-">
          </form>
<script src="index.js"></script>
<script>
function search(event) {
        event.preventDefault();

        const query = document.getElementById('searchBar').value;
        ipcRenderer.send('search-query', query);
      }
</script>

INDEX.JS :

const {ipcMain, app, BrowserWindow, remote } = require('electron');
let num = 0;

//code to create electron window

const checkForUpdates = () => {
ipcMain.on('search-query', (query) => {
      console.log(`Received search query: ${query}`);
    });}
setInterval(checkForUpdates, 300);

很抱歉,我无法提供有关为什么它不起作用的更多信息,因为我觉得一切都很好。如果需要,我可以提供有关 html 和 javascript 文件的更多信息。

javascript html electron
© www.soinside.com 2019 - 2024. All rights reserved.