electron: Injecting jQuery script into webview returns referenceError for $

I am trying to show a portion of a webpage into webview. To do this I inject a script into the body of the webpage in this way:

webview.executeJavaScript("$('body').css({'left': '" + left + "', 'top': '" + top + "' })" );

But in the console log I get the following error:

ReferenceError: $ is not defined.

The view: <webview ng-src="{{trustSrc(webpage.url)}}" id="{{webpage.name}}" partition="persist:test" nodeintegration></webview>

I use jquery in my project and it works fine but it does not work inside the webview. Is there a workaround for this issue.?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@Beslinda, you can also include jQuery by:

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

<script>window.$ = window.jQuery = require('./node_modules/jquery/dist/jquery.min.js');</script>