I'm following the The App Extension Guide: Accessing a Webpage to extract some content from a page.
Is it possible to use jQuery inside my javascript file and if so how?
I was able to inject jQuery into the page but was not able to successfully determine the time when I could run jQuery code after that. DOMNodeInserted executes but probably in a different context than page DOM.
MyExtensionJavaScriptClass.prototype = {
run: function(arguments) {
var my_awesome_script = document.createElement("script");
my_awesome_script.setAttribute("src","//code.jquery.com/jquery-1.11.0.min.js");
if (my_awesome_script.addEventListener) {
my_awesome_script.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
document.head.appendChild(my_awesome_script);
function OnNodeInserted (event) {
// event comes out undefined and $ is also undefined
$(document).on('paste', function(e){ alert('You just pasted!') });
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.