1

I want to semi-automate some actions.

I want the JQuery library to be loaded in a certain page, to allow me to easier manipulate/query the DOM, to get some data. The page is not under my control, but I don't want to write a crawler for it....I just want to manually crawl the data, from the console.

Can I somehow make my console download and execute the script here ""https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"?

If not, why not?

vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • Please refer http://stackoverflow.com/questions/10934234/jquery-linking-external-js-file-not-working – sathya Jun 20 '16 at 06:54
  • 2
    Check here [link](http://stackoverflow.com/questions/7474354/include-jquery-in-the-javascript-console) – Suni Jun 20 '16 at 07:00

2 Answers2

3

You can make your console download and execute scripts by appending a script tag with the src of the script.

var scriptTag = document.createElement("script");
scriptTag.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js");
document.body.appendChild(scriptTag);
Emil S. Jørgensen
  • 6,216
  • 1
  • 15
  • 28
2

Yes, you can. Paste this in your console:

    var script = document.createElement('script');
script.onload = function() {
  alert("Script loaded and ready");
};
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);

From here:document.createElement("script") synchronously

Community
  • 1
  • 1
grateful
  • 1,128
  • 13
  • 25