Javascript 如何在不暴露节点集成的情况下将窗体窗口连接到Electron应用程序
对Electron是新手,无法找到有用的线索 我只需要能够将窗口中的表单连接到我的应用程序 这是主文件,我只想使用一个预加载文件将单击事件连接到一个简单的控制台日志。只是一个概念上的证明,将两者联系起来Javascript 如何在不暴露节点集成的情况下将窗体窗口连接到Electron应用程序,javascript,electron,Javascript,Electron,对Electron是新手,无法找到有用的线索 我只需要能够将窗口中的表单连接到我的应用程序 这是主文件,我只想使用一个预加载文件将单击事件连接到一个简单的控制台日志。只是一个概念上的证明,将两者联系起来 // main.js const createAddWindow = () => { const preload = url.pathToFileURL('preload.js') addWindow = new BrowserWindow({ width: 500
// main.js
const createAddWindow = () => {
const preload = url.pathToFileURL('preload.js')
addWindow = new BrowserWindow({
width: 500,
height: 200,
title: "Best title you've ever seen",
webPreferences: {
preload: preload.href
}
})
const addWindowPath = url.pathToFileURL('addWindow.html')
addWindow.loadURL(addWindowPath.href)
// Garbage collection
addWindow.on('close', () => {
addWindow = null
})
}
这是预加载文件
// preload.js
const form = document.querySelector('form')
form.addEventListener('submit', (e) => {
e.preventDefault()
console.log('123')
})
这是addWindow文件
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dumb Doc title</title>
</head>
<body>
<h1>This is a window to add stuff</h1>
<form>
<div>
<label>Enter Item</label>
<input type="text" id='item' autofocus />
<button type="submit">add item</button>
</div>
</form>
<script>
</script>
</body>
</html>
哑文档标题
这是一个添加内容的窗口
输入项目
添加项
按钮的解除行为仍然存在,并且没有任何控制台日志记录。只是想知道如何在构建窗口时不暴露节点集成而做到这一点,除非您希望在应用程序中使用节点模块,否则不需要使用preload.js文件。你想用你的表格完成什么?