Integrate jQuery into a electron app

风流意气都作罢 提交于 2019-12-03 07:38:01

While using electron, some additional symbols are also inserted into DOM causing problems. So, you can use jquery as follow

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js" onload="window.$ = window.jQuery = module.exports;"></script>

Notice the code inside "onload".

When you call require inside index.js, or the main process, it's looking for the node module. So you'll need to install jQuery via npm and save it as a dependency in your apps package.json file.

npm install jquery --save

Then your index.js should theoretically see it just fine using

let $ = require('jquery');
mainWindow.$ = $;

Refer 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.

<script src="./jquery.min.js"></script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!