本文介绍了遇到错误时防止Javascript停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我们的产品将脚本插入到客户的网站中,就像一个实时聊天框.

Our product inserts a script into client's websites, kind of like a live chat box.

通常,客户的网站上有错误的JavaScript,这也会停止我们的代码(遇到错误时,浏览器会停止执行).即使控制台中有未定义的方法或变量之类的错误,有什么方法可以使我们的代码仍然执行?

Often, clients' websites have buggy javascript that also stops our code (the browser stops execution when errors are encountered). Is there any way to make our code still execute even though there are errors in the console about things like undefined methods or variables?

感谢您的帮助.

推荐答案

正如其他人所说,在发生错误后继续操作可能不是最好的选择,但是您可以尝试以下操作:

As others have said, continuing after an error might not be the best thing to do but you can try this:

function ignoreerror()
{
   return true
}
window.onerror=ignoreerror();

更多详细信息此处

Opera的页面包含更多详细信息

Opera has a page with more details

Browsers supporting window.onerror
Chrome 13+
Firefox 6.0+
Internet Explorer 5.5+
Opera 11.60+
Safari 5.1+

这篇关于遇到错误时防止Javascript停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:48