40

How can I load a javascript file via Firebug console ?

This would be useful in development, so I don't have to modify the html code to load the script.

3 Answers 3

62
var script = document.createElement("script");
script.src = "http://whatever.com/js/my/script.js";
document.body.appendChild(script);
Sign up to request clarification or add additional context in comments.

1 Comment

hm ok, doing it the hard way.
20

A very handy command is include();

include("http://code.jquery.com/jquery-latest.min.js");

Read more about include() command

2 Comments

I tried that in the Firefox inspector on twitter's homepage and got: ReferenceError: include is not defined.
@isomorphismes Because that is a special command for the Firebug Console. See the link provided by Ahmad and this for the other ones: getfirebug.com/wiki/index.php/Command_Line_API
17

Just ran into the same problem, and - as jQuery is used in the project anyway - I decided to do a simple:

$.getScript('example.js')

Or:

$.getScript('example.js', function () { doSomethingOnceLoaded(); })

Alternatively, I may code JavaScript directly in Firebug, using the console with the text entry pane on the right side. Activate it with the triangle button in the lower right hand corner.

1 Comment

As a jQuery user, I loved this solution. I didn't know about getScript(). Very nice. I also use the jQuerify plugin for Firebug. With that, I can quickly load jQuery on a page that doesn't have it, then use your solution to load additional libraries. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.