How to run jQuery directly on any page in the browser?

后端 未结 8 691
你的背包
你的背包 2021-01-31 21:17

Is there some programmatic way (or maybe a browser plugin) that allows users to arbitrarily run any jQuery they want on a webpage that is currently loaded in their browser?

8条回答
  •  逝去的感伤
    2021-01-31 22:11

    You can use Chrome's console to do it. If you're using Chrome, right click the page, then click "Inspect Element." Go over to the "Console" tab and try running $ === jQuery. If you don't get an error and the result is true, you've got jQuery.

    If not, run the following to add jQuery to a page:

    var body = document.getElementsByTagName("body")[0];
    var script = document.createElement('script');
    script.type = "text/javascript";
    script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
    body.appendChild(script);
    

    After running these commands, jQuery should be loaded into any web page and ready for use in the console :)

    The above code should work for any browser with a JavaScript console.

    Alternatively, there are userscripts (like Greasemonkey and FireQuery) which, if jQuery isn't included on the page, automatically run the above code to inject jQuery to make it easy for you to script and hack on other people's pages.

提交回复
热议问题