Run jQuery on console on a page that doesn’t have jQuery

Asked

Viewed 784 times

3

Often, jQuery is very useful to take some statistics off the page and others cositas, just make a $('.elemento').each(callback) and you can already start to know what is happening on the page.

The problem is that this relies on the page doing the load jQuery; if not, there is no way, it has to be pure JS.

Is there any way force jQ loading to any page, e.g., Google?

1 answer

4


There is a way yes, as we can see in Soen’s reply: Include jQuery in the Javascript Console.

Just do Paste code on the console and jQuery will be loaded. We can then use it freely on the console. Slightly adapted:

var jq = document.createElement('script');
jq.src = "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... dar um tempinho pro script carregar
setTimeout( function(){
    jQuery.noConflict();
    $=jQuery;
    console.log('Carregado jQuery v' + $.fn.jquery);
}, 3000);

To facilitate the use of snippet we can keep it as a... snippet!, within the own Chrome Developer Tools:


console snippets injecting jquery

  • Instead of setTimeout, you can use jq.onload = Function...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.