1

I have a question, and I can't solved. I need get from dev console, the total of errors and warning existent on it.

I have this code to detect erros on JS:

window.onerror = function(error, url, line) {   
    $('body').append('<div class="teste">'+error+' <br/> on '+url+'<br/>in line: '+line+'</div>');
};

This send to me the error description, url of file and line, but if for example, I have a wrong path of one image on console, I want get him, it's possible?

PS: I need use the errors on console like html on my page. Errors like:

Font from origin 'http://fonts.gstatic.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource......

1 Answers1

0

You need to use an error event handler for each image element to do that

$('img').on('error', function(){
   console.log('Error loading: ' ,this.src);
});
charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • Thanks, but this is not what I searching for.. I need "print" the logs from console into a html div – Diogo Esteves Feb 18 '16 at 17:48
  • then simply change the code in the callback and do an append instead of log to console – charlietfl Feb 18 '16 at 17:53
  • No, for example, I have this on my console:`Font from origin 'http://fonts.gstatic.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin...` and I want use this on my html – Diogo Esteves Feb 18 '16 at 17:58
  • You would need error handlers on all those resources also. Those are not javascript errors so you need to apply error handlers to all applicable tags you want. I showed you how to do it for image... do it for `` too. As for what's being imported inside css that is far more complex – charlietfl Feb 18 '16 at 18:04
  • How? using each by every link and script for example? – Diogo Esteves Feb 18 '16 at 18:05