Include jQuery in the JavaScript Console
Is there an easy way to include jQuery in the Chrome JavaScript console for sites that do not use it? For example, on a website I would like to get the number of rows in a table. I know this is really easy with jQuery.
$('element').length;
The site does not use jQuery. Can I add it in from the command line?
Run this in your browser's JavaScript console, then jQuery should be available...
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();
NOTE: if the site has scripts that conflict with jQuery (other libs, etc.) you could still run into problems.
Update:
Making the best better, creating a Bookmark makes it really convenient, let's do it, and a little feedback is great too:
javascript:(function(e,s){e.src=s;e.onload=function(){jQuery.noConflict();console.log('jQuery injected')};document.head.appendChild(e);})(document.createElement('script'),'//code.jquery.com/jquery-latest.min.js')
Below is the formatted code:
javascript: (function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
console.log('jQuery injected');
};
document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')
Here the official jQuery CDN URL is used, feel free to use your own CDN/version.
Run this in your console
var script = document.createElement('script');script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(script);
It creates new script tag, fills it with jQuery and appends to head
Use the jQueryify booklet:
http://marklets.com/jQuerify.aspx
Instead of copy pasting the code in the other answers, this'll make it a clickable bookmark.
链接地址: http://www.djcxy.com/p/3934.html上一篇: 使用JQuery删除禁用的属性?