2

I'm currently working on a web application with Electron. If I open the app in the normal Chrome browser it works as expected: click as click, touch as touch.

But if I package it with electron it does not work right - it always returns touchstart = true, even though I'm not in the dev tools in the responsive view or on a device that is touchable - so clicks won't work.

This is the beginning of my javascript file:

var selectEvents = (function () {
    if ('ontouchstart' in document === true) {
        return "touchstart";
    } else {
        return "click";
    }
})();

and this is my main.js for electron

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();
    }
})

In my HTML I created a button with the id 'next-button-1' After an interaction it checks in the script if it's a click or a touchevent normally.

$('#next-button-1').on(selectEvents, function () {
...
}

Searched now quite a while on google but didn't find a working solution. Maybe you could help me

1 Answers1

0

Added "click touchstart" to the first return. Now it works also on Electron. Hope this is reliable.

var selectEvents = (function () {
    if ('ontouchstart' in document === true) {
        return "click touchstart";
    } else {
        return "click";
    }
})();