Skip to main content

jQuery Code Only Runs When Firebug is Open

By Sam Deering



Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95


So you may be wondering why your jQuery Code is only running when firebug is open on your browser. Well, this could be because you have used console.log commands in your code and the jQuery code is failing because the console doesn’t exist.

To fix this simple put your console.log and firebug commands inside the following code:

if (window.console) {

Ensure no JavaScript errors are thrown for browsers without Firebug installed

if (!window.console || !console.firebug)
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}

Turn it into a debug function sir? [js] function debug(text) { if ((typeof(Debug) !== 'undefined') && Debug.writeln) { Debug.writeln(text); } if (window.console && window.console.log) { window.console.log(text); } if (window.opera) { window.opera.postError(text); } if (window.debugService) { window.debugService.trace(text); } }

If console available, log the error

if (typeof(console) != 'undefined' && typeof(console.log) == 'function') {
	// If console available, log the error.
	console.log('Problem hiding the form', e);

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

Learn valuable skills with a practical introduction to Python programming!

Give yourself more options and write higher quality CSS with CSS Optimization Basics.