Injecting javascript with Firebug
Sometimes you may want to include a Javascript file on a live web page to see how things will work or to try new things. Usually you would do this by editing the source code including the new file but there is a fastest way if you have Firefox with Firebug. Just run the following code in the Javascript console:
-
var headID = document.getElementsByTagName("head")[0];
-
var newScript = document.createElement('script');
-
newScript.type = 'text/javascript';
-
newScript.src = 'http://enekoalonso.com/lib/jquery-1.2.6.min.js';
-
headID.appendChild(newScript);
Here I am loading the jQuery library from my own server, but I could load any Javascript from any server on the net. The best is this will work on any website, whenever you have access to the server or not. Once you have the Javascript loaded you can use it right away. For example, here on this blog I could use jQuery to check how the header will look if its height was only 100px by running the next command on the console:
-
jQuery('#header').css('height',100);
Yep, it won’t look very good, right? Try it! You have to see it by yourself. Firefox is great. Firebug is awesome. And Firebug’s Javascript console is the best thing ever!
PS: In case you are wondering, the Javascript file injected will exist only on the current browser session.
