闻心阁

一蓑烟雨看苍生,半壶浊酒笑红尘

Inject jQuery into Any Webpage

2016-10-08 约 1 分钟读完 搬砖秘籍

Even MVVM framework is more and more popular in the web front developments, but the strength of jQuery cannot be replaceable. Sometimes, we need the jQuery’s useful APIs to achieve some complex actions, but many webpages give up jQuery, so some skills is needed to inject the jQuery into the webpages which had abandon the jQuery library.

I find a good solution and share it, here is the code:

if(!window.jQuery){
  var script = document.createElement('script');
  script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js";
  script.type = 'text/javascript';
  document.getElementsByTagName('head')[0].appendChild(script);
}

Just copy the code into the Chrome Devloper tool, and the jQuery would be loaded into the webpage :-)