5

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?

4

2 回答 2

3

是的,Safari 确实支持window.onerror您发布的函数签名:function(errorMsg, url, line),大概是在 2011 年webkit 添加它时

但是,它目前不支持包含堆栈跟踪和列号的新签名:function(errorMsg, url, line, column, errorObject). 然而,这似乎正在进行中:https ://bugs.webkit.org/show_bug.cgi?id=55092

Firefox 和 Chrome 已经支持新语法:

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

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

于 2014-04-02T20:13:44.807 回答
1

现在所有主要浏览器支持该语法function(errorMsg, url, line, column, errorObject)。有关更多信息,请参阅文章:https ://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror

于 2018-11-14T21:37:54.100 回答