我目前正在与Electron一起开发一个web应用程序。如果我在普通的Chrome浏览器中打开应用程序,它会像预期的那样工作:点击时点击,触摸时触摸。
但是如果我用电子封装它,它就不能正常工作--它总是返回touchstart = true,即使我不在响应视图中的dev工具中,也不在可触摸的设备上--所以点击不起作用。
这是我的javascript文件的开头:
var selectEvents = (function () {
if ('ontouchstart' in document === true) {
return "touchstart";
} else {
return "click";
}
})();这是我的电子main.js
const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');
// init win
let win;
function createWindow(){
// create browser window
win = new BrowserWindow({width:3840, height: 1080, icon:__dirname+'/images/icons/bosch_logo.jpg', kiosk: true});
// load index.html
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
// open devtools
win.webContents.openDevTools();
win.on('closed', () => {
win = null;
});
}
// Run create window function
app.on('ready', createWindow);
// quit when all windows are closed
app.on('window-all-closed', () => {
// check for mac osx
if(process.platform !== 'darwin') {
app.quit();
}
})在我的HTML中,我创建了一个id为'next- button -1‘的按钮,在一次交互之后,它会在脚本中检查它是否是正常的点击或触摸事件。
$('#next-button-1').on(selectEvents, function () {
...
}现在在谷歌上搜索了很长一段时间,但没有找到一个有效的解决方案。也许你能帮我
发布于 2018-12-19 18:06:44
在第一个返回中添加了"click touchstart“。现在,它也可以在Electron上运行。希望这是可靠的。
var selectEvents = (function () {
if ('ontouchstart' in document === true) {
return "click touchstart";
} else {
return "click";
}
})();https://stackoverflow.com/questions/53848047
复制相似问题