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)
@Beslinda, you can also include jQuery by:
@Beslinda have a look at this: https://github.com/electron/electron/issues/2048#issuecomment-115092053
<script>window.$ = window.jQuery = require('./node_modules/jquery/dist/jquery.min.js');</script>