我在电子反应应用程序中有一个文本输入字段。windows.alert() 被用于通过在给定条件下更改状态的警报。但是在发出警报后,一个完全独立的表单中的输入文本字段将不允许用户在不点击应用程序然后再返回的情况下输入数据。
我目前确实有一个解决方法,即使用电子的 ipcRenderer 和 ipcMain 发出警报,但样式与应用程序的其余部分不匹配。有没有办法处理不会阻止数据输入到文本输入字段的 windows.alert()?是什么导致 windows.alert() 阻止将数据输入到文本输入中?
之前的代码示例:
function doSomething(value) {
let array = otherArray;
if (array.length == 0) {
//The below was blocking typing into <input> in a completely separate form.
window.alert("Please add expected value first")
}
}
使用 preload.js 和 ipcMain 中的 ipcRenderer 解决代码:
function doSomething(value) {
let array = otherArray;
if (array.length == 0) {
window.api.send("send-alert", "Please add expected value first")
}
}
//in main.js
ipcMain.on("send-alert", (event, incomingMessage)=> {
let options = {
message: incomingMessage
}
dialog.showMessageBox(mainBrowserWindow, options)
}