Javascript Alerts to Display Console Errors & Messages

Allure Web Solutions Code Snippet

Sometimes you don’t have access to a JavaScript console and need to display console errors some other way. This could be a common case for ┬ámobile development. With the below snippet, console errors will appear within alerts real time.

if (typeof console  != "undefined") 
    if (typeof console.log != 'undefined')
        console.olog = console.log;
    else
        console.olog = function() {};

console.log = function(message) {
    console.olog(message);
    alert('
' + message + '
');
};
console.error = console.debug = console.info = console.log

// Credit: http://stackoverflow.com/a/6604660/3602355

Demo

Mike Doubintchik

Author Mike Doubintchik

More posts by Mike Doubintchik

Leave a Reply