我在使用最新版本的 Electron 时遇到此错误。我在主 javascript 文件中将 nodeIntegration 设置为 true 。我已从工作的 Electron 应用程序复制并粘贴了此代码,但它似乎不适用于我的新应用程序。
电子版本:^12.0.0
我的主要JS
//Require Electron
const { BrowserWindow, app, autoUpdater, globalShortcut, ipcMain } = require('electron');
const main = require('electron-reload');
//Electron reload
const electron_reload = require('electron-reload')(__dirname);
//Disable security warnings
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
//Main window
function createMain() {
const main = new BrowserWindow({
minWidth: 425,
minHeight: 524,
width: 1600,
height: 900,
frame: null,
icon: './assets/icon.png',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
nodeIntegrationInSubFrames: true,
enableRemoteModule: true,
}
});
main.loadFile('./HTML/index.html');
main.setMenu(null);
main.webContents.toggleDevTools();
main.webContents.on('did-finish-load', function …Run Code Online (Sandbox Code Playgroud) 我想通过js关闭Electron App。
"electron": "^13.1.7"
Run Code Online (Sandbox Code Playgroud)
我仔细阅读了这些问题:
但这些都不适合我。
以下所有测试均基于官方的电子快速启动
索引.html
"electron": "^13.1.7"
Run Code Online (Sandbox Code Playgroud)
main.js
<body>
<button id="close-app">
close
</button>
<script src="./renderer.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
没有任何影响或错误。
似乎代码从未运行过,我console.log('run')在上面添加了一个addEventListener,但控制台中没有打印任何内容。
(不改变官方的电子快速启动,只改变preload.js和index.html)
索引.html
与上面相同
预加载.js
const { app } = require('electron');
window.addEventListener('DOMContentLoaded', () => {
document.getElementById("close-app").addEventListener("click", function (e) {
app.quit();
})
})
Run Code Online (Sandbox Code Playgroud)
Uncaught TypeError: Cannot read property 'quit' of undefined只
得到
那么,如何通过js关闭Electron App呢?
非常感谢任何人的帮助!
无论如何都要检查链接,无论是下载链接,如http://ipv4.download.thinkbroadband.com/5MB.zip
或普通网络,如打开https://www.google.com
目前我正在使用 Electron 并想检查链接是否为下载链接,它将下载而不是打开新的浏览器,但如果不是,它将在浏览器窗口中打开
在JS中安装npm uuid后,我无法调用uuid函数,使用电子
这是我安装时终端上的消息,我不知道这是否正确安装
$ npm install uuid
npm WARN pemrograman_visual2@1.0.0 No description
npm WARN pemrograman_visual2@1.0.0 No repository field.
+ uuid@7.0.3
updated 1 package and audited 120 packages in 1.746s
2 packages are looking for funding
run `npm fund` for details
found 1 low severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
Run Code Online (Sandbox Code Playgroud)
这是我调用函数的地方
ipcMain.on("appointment:create", (event, appointment) => {
appointment["id"] = uuid();
appointment["done"] = 0;
allAppointment.push(appointment);
CreateWindow.close();
console.log(allAppointment);
});
Run Code Online (Sandbox Code Playgroud)
但是当我使用 $npm start 运行程序时,它说 TypeError: uuid is …
我使用 jquery 获取 html img 元素的路径,如下所示:
path = $("#img_elemnt_id).attr('src')
Run Code Online (Sandbox Code Playgroud)
它给了我一个字符串
path = "C:\User\pic.jpg"
Run Code Online (Sandbox Code Playgroud)
我需要在函数中使用该字符串,但仅当路径如下时才有效
path ="C:\\User\\pic.jpg"
Run Code Online (Sandbox Code Playgroud)
知道如何做到这一点吗?
更新:您的答案不起作用。
path = "C:\\User\\pic.jpg"
Run Code Online (Sandbox Code Playgroud)
在该功能中有效,但您的答案不起作用。
path = "C:\User\pic.jpg"
path = path.replace('\\,'\\\\')
console.log(path)
Run Code Online (Sandbox Code Playgroud)
输出
C:Userpic.jpg
Run Code Online (Sandbox Code Playgroud)