You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
everytime loading jquery from render side (any.html) via dom <script src="jquery.js"></script> resulting "Uncaught ReferenceError: jQuery is not defined" or "Uncaught Error: ... requires jQuery";
but if I load jQuery via require:
<script>var$=jQuery=require('jquery');// as node_modules/* * or localy load. * var $ = jQuery = require('./jquery'); */</script>
(on every page) It was fine!, but module.exports get polluted by jQuery's methods
so every page either local or external site whom use jQuery would fail to properly load since jQuery header:
(function(global,factory){if(typeofmodule==="object"&&typeofmodule.exports==="object"){// For CommonJS and CommonJS-like environments where a proper window is present,// execute the factory and get jQuery// For environments that do not inherently posses a window with a document// (such as Node.js), expose a jQuery-making factory as module.exports// This accentuates the need for the creation of a real window// e.g. var jQuery = require("jquery")(window);// See ticket #14549 for more infomodule.exports=global.document ?
factory(global,true) :
function(w){if(!w.document){thrownewError("jQuery requires a window with a document");}returnfactory(w);};}else{factory(global);}// Pass this if window is not defined yet}(typeofwindow!=="undefined" ? window : this,function(window,noGlobal){
are they any solution for this kind of matter?
Thanks.
I just cooked up a solution to this, as I was having the same issue.
Simply include this script immediately after your <script src="jquery.js"></script>:
<script>try{$=jQuery=module.exports;// If you want module.exports to be empty, uncomment:// module.exports = {};}catch(e){}</script>
Reacted by HSGorman, Daniel Salamon, Lexy Feito, Emiliano Carrillo, Aizaz Ahmad, emad fanaeian, Daniel Castro Fernández, Himitsu, Celeste Capece, Julien SCHMIDT and 1 more
Reacted by Chánh Đại
Reacted by Aizaz Ahmad, emad fanaeian, Himitsu, Celeste Capece and Julien SCHMIDT
@deecoolist , The problem you have is that jQuery is attaching itself as a global variable on the window object of your mainWindow.... however, the main script you are using with mainWindow has no notion of the "window" object, as there could be multiple windows to which you may refer. In this case, your window object is some descendant of your mainWindow variable.
For this to work, you're going to have to reorganize your code so that the jQuery variable is a global not attached to the window, or use some kind of injection or message-passing as you have done here.
@deecoolist have you found a solution to make JQuery a global variable? it would help me for my app, i got the same issue with JQuery and i need it to load a website on a webview
Reacted by hongtao510, Paul O'Fallon, Oded Breiner, Luis William, Didier Baquier, Vagnerlandio Nunes, Veit Kunz, Nikhil M, qq7, Jose Machava and 3 more
Activity
jsonnull commentedon May 22, 2014
I just cooked up a solution to this, as I was having the same issue.
Simply include this script immediately after your
<script src="jquery.js"></script>:deecoolist commentedon May 22, 2014
Thanks @jsonnull , i have try that on local file surely did work, but when you loadUrl from external site e.g. http://getbootstrap.com/index.html it seem wont do the trick. 👍 I think the bug at libchromiumcontent. I have try some others tricks like inject the script from main.js;
right after instantiate BrowserWindow;
first load ok, but next load are mess.
jsonnull commentedon May 22, 2014
@deecoolist , The problem you have is that jQuery is attaching itself as a global variable on the window object of your mainWindow.... however, the main script you are using with mainWindow has no notion of the "window" object, as there could be multiple windows to which you may refer. In this case, your window object is some descendant of your mainWindow variable.
For this to work, you're going to have to reorganize your code so that the jQuery variable is a global not attached to the window, or use some kind of injection or message-passing as you have done here.
deecoolist commentedon May 22, 2014
@jsonnull thanks I got your ideas.
ranmocy commentedon Jun 2, 2014
As #254 is a better solution:
jsonnull commentedon Jun 2, 2014
@ronmocy Only if you're not going to serve your HTML outside of atom-shell.
ranmocy commentedon Jun 2, 2014
@jsonnull You mean reuse the code right? How about include the jQuery again in the normal way?
gliurn commentedon Feb 27, 2015
@deecoolist have you found a solution to make JQuery a global variable? it would help me for my app, i got the same issue with JQuery and i need it to load a website on a webview
DogsForArms commentedon Mar 17, 2015
Thanks very much for this quick solution.
Fix jQuery reference error.
SantoshSrinivas79 commentedon Jun 24, 2015
@deecoolist what was the solution to this? i need the same functionality like you've described
rigelk commentedon Aug 19, 2015
Just for reference @fountainhead , it did the trick for me :
eric-naguras commentedon Aug 21, 2015
Thanks rigelk.
This worked for me.
My app works on OSX but would give jquery module not found errors on Windows.
Your solution solved that.
raghav-axero commentedon Aug 27, 2015
Hi,
I added the following code
onload="window.$ = window.jQuery = module.exports
on external page:
It did add the jQuery object but with the value of module.exports.
What about the core jQuery file code?
I can't access any functions which jQuery exposes after that like jQuery.fn etc
Can anyone suggest any solution for adding jQuery.js on an external site loaded in Electron via:
mainWindow.loadUrl('http://mysite.com/external.html');
Fix jQuery for electron
thonatos commentedon Oct 18, 2015
I use this in script :
var $ = require(path.join(process.cwd(), 'frontend/assets/vendors/jquery/dist/jquery'));
mendo9 commentedon May 18, 2016
I found this worked to load jquery in window of an external website.
main.js
preload.js
Bronts commentedon Oct 28, 2016
@rigelk I use your solution but I modified like this
update:
with
module.exportit will notice module is not defined if setThanks for your solution.
This works fine for loading remote url with jQurey.
AizazAhmad commentedon Feb 16, 2018
Thanks @jsonnull. i was stuck to load custom jquery. it takes mine 2 days. after that i got ur solution: $ = jQuery = module.exports;