2

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?

kfateem
  • 323
  • 2
  • 8

1 Answers1

0

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!') });
     }
sergeSF
  • 3
  • 2