How to add JQuery to Electron?



  • I'm a web developer, I've tried meths in an English post, but... none works, I want to add JQuery No electon.

    I've used this without window.$ doesn't work.

    <script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
    

    I tried it with window.$ it working but stopped working for some unknown reason...

    <script src='https://code.jquery.com/jquery-3.2.1.min.js' onclick='window.$ = window.jQuery = module.exports;'></script>
    

    Someone knows script to do JQuery work?

    I want to leave him in my main.js (index.js) instead of leaving on a web page if possible. If you don't, I'll leave it on the same page.



  • You need to use https://www.npmjs.com/package/jQuery jQuery so you can use it on the server-side.

    See below:

    npm install jQuery
    

    Then just include the jQuery package (as https://pt.stackoverflow.com/questions/259633/como-adicionar-jquery-no-electron#comment532592_259633 by Anderson Carlos Woss):

    var $ = require('jQuery');
    

    In the illustration example below, I include the package in the file index.html, however, you can include in your main.js or in a separate window.

    <script>
        // You can also require other files to run in this process
        require('./renderer.js')
        var $ = require('jQuery');
    
    // Pode usar o jQuery normalmente agora.
    $(document).ready(
        function() 
        { 
            $("&lt;h1&gt;Test jQuery&lt;/h1&gt;").appendTo('body');
        }
    );
    

    </script>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2