Search code examples
javascriptjqueryonerror

get error message from jquery's eventData object


I currently have a javascript error handler like this:

window.onerror = function(msg, url, line){ //stuff }};

But I would like to be able to use jquery to attach to onerror like so:

$(window).error(function(evtData){//stuff});

My question is, from jquery's eventData object, how can i get the error's message, url, and line number, as I did in the non-jquery function?

Thanks in advance.


Solution

  • From jQuery docs.

    Note: A jQuery error event handler should not be attached to the window object. The browser fires the window's error event when a script error occurs. However, the window error event receives different arguments and has different return value requirements than conventional event handlers. Use window.onerror instead.

    Refernce: http://api.jquery.com/error/