Does Safari support javascript window.onerror?

痞子三分冷 提交于 2019-12-12 12:29:50

问题


I have a function attached to window.onerror

 window.onerror = function(errorMsg, url, line) {
                window.alert('asdf');
                };";

This works fine in firefox, chrome and IE, but it doesn't work in safari. From some digging I read somewhere that safari does not support onerror. The post however was a few years old. Does safari currently support onerror?

If not, is there a workaround?


回答1:


Yes, Safari does support window.onerror with the function signature you posted: function(errorMsg, url, line), presumably since about 2011 when webkit added it.

However it does not currently support the new signature which includes the stack trace and column number: function(errorMsg, url, line, column, errorObject). This appears to be in the works, however: https://bugs.webkit.org/show_bug.cgi?id=55092

Firefox and Chrome already support the new syntax:

https://bugzilla.mozilla.org/show_bug.cgi?id=355430

https://code.google.com/p/chromium/issues/detail?id=147127




回答2:


All major browsers now support the syntax function(errorMsg, url, line, column, errorObject). For more info see the article: https://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror



来源:https://stackoverflow.com/questions/19933961/does-safari-support-javascript-window-onerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!