Skip to main content

Javascript Alerts to Display Console Errors & Messages

By December 9, 2016Blog, Javascript, Snippets
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

allure

Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017