我正在尝试为工作中的同事制作一个简单的桌面应用程序。我设计了界面,我正在使用 webview。我用 frame: false 命令删除了框架,制作了一个自定义设计框架,并用 ipcrenderer 控制按钮。到目前为止,一切进展顺利。但是,我在我的 index.html 中使用引导程序,我必须使用 jquery。我在这里使用标签分区。
如果我在 webPreferences 中执行 nodeintegration:false,则引导和 jquery 功能,即选项卡部分,可以正常工作。但我使用 ipcrenderer 的按钮不起作用。
相反,如果我将其更改为 nodeintegration: true,我的所有 ipcrenderer 按钮都可以正常工作,但我的选项卡部分,即需要 jquery 的其他菜单,将停止工作。
如何同时运行 ipcrenderer 进程和 jquery 进程。
我这几天一直在处理这个问题,但没有得到解决。
我尝试了各种解决方法,但我无法获得正常工作的结果。我怎么解决这个问题。谢谢您最好的问候。
索引.html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="script-src 'self';">
<title>MY APP</title>
<link rel="stylesheet" href="./js/bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="./css/electron_appstyle.css">
<script src="./js/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="./js/electron_appfunctions.js" async type="text/javascript"></script>
</head>
<body>
.....
.....
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="./js/bootstrap/popper.min.js" async type="text/javascript"></script>
<script src="./js/bootstrap/bootstrap.min.js" async type="text/javascript"></script>
<script src="./js/bootstrap/bootstrap.bundle.min.js" async type="text/javascript"></script>
</body>
</html>
main.js 的一部分
const { app, BrowserWindow, ipcMain} = require('electron');
const { join } = require('path');
const path = require('path');
function createWindow () {
win = new BrowserWindow({
icon: path.join(__dirname, "icon.png"),
width: 960,
height: 600,
minWidth: 940,
minHeight: 560,
frame: false,
resizable: true,
autoHideMenuBar: true,
x: 0,
y: 0,
webPreferences: {
preload: path.join(__dirname, './preload.js'),
enableRemoteModule: true,
nodeIntegration: false,
contextIsolation: false,
disablewebsecurity: false,
webviewTag: true,
allowRunningInsecureContent: false,
allowpopups: false,
devTools: true
},
show: false,
})
win.loadFile(join(__dirname, "src/index.html"));
win.on("ready-to-show", () => {
// RUN
win.show()
});
}