Sign in

Does jQuery code in HTML page not run when electron runs program?

Oscar edited in Tue, 09 Aug 2022

There is no problem running HTML page with browser, and there is no problem running page style with electron, but jQuery method is not implemented. After checking the data, modify the reference line code of jQuery file to < script > window. $= window.jQuery = require("./js/ jquery.min.js "); < / script > but it still doesn't work. I don't know how to debug electron?

4 Replies
commented on Tue, 09 Aug 2022

Do not use the file suffix require (". / JS) in require/ jquery.min.js ") -> require("./js/ jquery.min ")

In addition, opening the debug tool in electron is BrowserWindow.openDevTools Specific can check the official documents

commented on Tue, 09 Aug 2022

Pay attention to the reference order of jquey, put it first.

commented on Tue, 09 Aug 2022

I'm sorry, this problem has been discussed abroad. I was just passing by to carry it, so that the future version of friends can solve the problem. Stackoverflow (by Dale harders) is the most concise solution for the message with the most votes

<!-- Insert this line above script imports --> < script > if ( typeof module === ' object ') { window . module = module ; module = undefined ;}</ script > <!-- normal script imports etc --> < script src =" scripts / jquery . min . js "></ script > < script src =" scripts / vendor . js "></ script > <!-- Insert this line after script imports --> < script > if ( window . module ) module = window . module ;</ script > See self question # two hundred and fifty-four @ Github

According to my unprofessional understanding, the main reason is that the HTML subroutine requests jQuery, but the whole domain is not installed, so even if you lose 12 gold medals, electron will not respond obediently. The method provided above is to tell electron that I don't need your node module tube to use this jQuery today, and the labor and capital set up another dedicated channel, ycyu-nobb. According to the original author, all third-party banks can subsidize the local law. I'm also testing myself. I've tried many times. Please let me go. (∥ ω ∥ three ∥ ω ∥)

Of course, it's also feasible to install jQuery in the whole domain. As chicory said on the first floor, the plug-in in in the whole domain can't carry the. JS sub file name.

commented on Wed, 10 Aug 2022

If you use browserwindow to open a page that is not developed by yourself, that is to say, you cannot modify the HTML code. It is recommended to use the preload property to preload the specified script before running other scripts on the page. Examples are as follows:


mainWindow = new BrowserWindow({
    webPreferences: {
      nodeIntegration: true,
      webSecurity: true,
      preload: path.resolve(path.join(__dirname, 'path/to/preload.js'))
    width: 900,
    height: 900


preload . js

document.addEventListener("DOMNodeInserted", function(event) {
    if (!!window && !(!!window.$)) {
        window.$ = window.jQuery = require('path/to/jquery.js');

Reference: jQuery issue on render side

lock This question has been locked and the reply function has been disabled.