jQuery Code Only Runs When Firebug is Open

Share this article

firebug1ie-sad

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) {
	console.log(text);
}

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() {}
}
[/js]

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 DeeringSam Deering
View Author

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.

jQuery
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form