【问题标题】:Error in Javascript causes page in IE to stop running javascriptJavascript 中的错误导致 IE 中的页面停止运行 javascript
【发布时间】:2011-09-19 15:46:57
【问题描述】:

在我的网站上,我引用了一个 javascript 文件,而在 IE 上,抛出了这个错误:

send: function (data) {
    /// <summary>Sends data over the connection</summary>
    /// <param name="data" type="String">The data to send over the connection</param>
    /// <returns type="signalR" />
    var connection = this;

    if (!connection.transport) {
        // Connection hasn't been started yet
        throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()";
    }

    connection.transport.send(connection, data);

    return connection;
},

throw 正在被 Internet Explorer 捕获,它似乎会阻止任何其他 javascript 运行。

我该怎么做才能使错误不会完全停止我页面上的所有内容?

【问题讨论】:

  • 异常有效,你在做什么需要禁用它?

标签: javascript internet-explorer throw signalr


【解决方案1】:

如果不想抛出异常,为什么还要使用 throw? 考虑这一点,如果您希望将异常用于记录目的:

if (!connection.transport) {
    // Connection hasn't been started yet
    setTimeout(function() {
        throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()"; 
    }, 0);
    return;
}

【讨论】:

猜你喜欢
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
  • 2012-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多