1

The issue here is that I'm using a javascript library that has a native error that keeps popping up when a certain group of buttons are pressed too many times (over a specific limit). The page then needs to be refreshed (For now until the native issue is worked out).

I have added this alert to my html, essentially I want it to pop up the moment when the console reports an error. (I am using Chrome)

<div class="alert alert-danger" role="alert" style="display:none;">Please Refresh Page</div>

To do this I would essentially use jquery like so:

$('.alert').fadeIn()

However I am unsure as to how I would trigger that simple jquery call. How could I listen in on the console, and when the console reports an error, call that jquery function to make that alert banner visible?

I have not been able to find a clear answer to my question, hopefully the StackOverflow Community has it! Thanks in advance.

Felix Dasgupta
  • 127
  • 1
  • 2
  • 10
  • possible duplicate of [Getting data from the browser's console using javascript](http://stackoverflow.com/questions/5056737/getting-data-from-the-browsers-console-using-javascript) – Manwal Aug 26 '15 at 15:38

1 Answers1

2

Using this link I got you're desired effects in this codepen by doing this:

window.onerror = function(error, url, line) {
    $('.alert').fadeIn();
};
Community
  • 1
  • 1
Jacob Petersen
  • 1,463
  • 1
  • 9
  • 17