我尝试使用window.loadurl在web中加载web应用程序,在html中加载webview。应用程序正在显示,但有不同的错误,如:
$ jquery not defined
Uncaught TypeError: $(...).daterangepicker is not a function
Uncaught TypeError: Cannot read property 'getContext' of undefined
我尝试了不同的方法,最终摆脱了未定义的$ jquery'错误。 为什么电子不能充当浏览器。此应用程序适用于所有浏览器。 如何将此Web应用程序加载到具有功能的电子设备中。 我的网络应用程序是:
www.mcgeoautomation.com
我的index.js文件是:
const electron = require('electron');
const app = electron.app;
var path=require('path');
const BrowserWindow = electron.BrowserWindow;
var mainWindow;
app.on('ready',function(){
mainWindow = new BrowserWindow({
width: 1024,
height: 768,
backgroundColor: '#2e2c29',
show:false,
});
mainWindow.loadURL(`file://${__dirname}/webView.html`);
mainWindow.maximize(true);
// mainWindow.setMenu(null);
mainWindow.once('ready-to-show',()=>{
mainWindow.show()
})
mainWindow.on('close', (e)=>{
app.quit();
});
});
package.json文件:
`{
"name": "crushmate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^1.7.9",
"jquery": "^3.2.1"
},
"devDependencies": {
"electron-prebuilt": "^1.4.13"
}
}`
请帮忙...... 此致...
答案 0 :(得分:0)
Electron不像常规浏览器那样处理jQuery
。你必须将它注入webview
。现在无法对此进行测试,但应该让您继续使用它。
的index.html
<!DOCTYPE html>
<html>
<head>
<title>jQuery injection into webview preload</title>
</head>
<body style="overflow:hidden;">
<webview id="webview" preload="./preload.js" src="http://www.mcgeoautomation.com" style="position:absolute;width:100%;height:100%;"></webview>
<script>
// need to have a script tag make webview work even if you don't plan to use it...
</script>
</body>
</html>
preload.js
window.onload = function() {
var script = document.createElement("script");
script.src = "https://code.jquery.com/jquery-2.1.4.min.js";
document.body.appendChild(script);
};
答案 1 :(得分:0)
我遇到了同样的问题,停用 nodeIntegration
为我解决了这个问题。
创建 BrowserWindow
时只需添加以下代码:
webPreferences: {
nodeIntegration: false
}
(使用的电子版本是“11.2.0”)