I'm trying to add jquery functionality to a desktop app written in electron
Using the electron-quick-start repo i'm adding the downloaded jquery file to the main.html
file like so:
<script> require("./jquery.min.js"); </script>
or so:
<script>window.$ = window.jQuery = require('./jquery.min.js');</script>
Then in the index.js
file i'm adding code in the createWindow
function, since that seems the proper place, but to be honest any place i try gets me the same error more or less.
mainWindow.$
is undefined
and the same goes for BrowserWindow
and app
mainWindow
is defined inside the createWindow
function like so:
mainWindow = new BrowserWindow({width: 800, height: 600})
and BrowserWindow is declared on top of the file like so:
const BrowserWindow = electron.BrowserWindow
Any idea where i'm going wrong, what declarations i should change/add?
Thanks in advance
When you call
require
insideindex.js
, or the main process, it's looking for the node module. So you'll need to installjQuery
via npm and save it as a dependency in your apps package.json file.Then your
index.js
should theoretically see it just fine usingRefer to the Node.JS section for installing jQuery. This is what Electron uses.
--
OLD ANSWER
Inside your
main.html
, just include the JavaScript like you would any traditional JS file.While using electron, some additional symbols are also inserted into DOM causing problems. So, you can use jquery as follow
Notice the code inside "onload".