【问题标题】:How to check for origin while using Eventsource in IE?在 IE 中使用 Eventsource 时如何检查来源?
【发布时间】:2016-03-21 15:26:59
【问题描述】:

我正在使用这个 polyfill 使服务器端事件 (EventSource) 与 IE 一起使用 - https://github.com/Yaffle/EventSource

效果很好,除了我无法检查来源,就像本教程推荐的那样(出于安全目的)http://www.html5rocks.com/en/tutorials/eventsource/basics/

这是来自 html5rocks 的代码

  source.addEventListener('message', function(e) {
  if (e.origin != 'http://example.com') {
    alert('Origin was not http://example.com');
    return;
  }
  ...
}, false);

有没有办法设置和检查原点,让它与 IE 一起工作?

【问题讨论】:

    标签: internet-explorer polyfills eventsource


    【解决方案1】:

    html5rocks 上的文章说应该检查原点,但这没有必要。

    警告“作者应该检查源属性”与 window.postMessage() 消息特别相关,而不是 EventSource 和 WebSocket。

    因为您将 URL 作为参数传递给 EventSource 的构造函数。

    https://www.w3.org/Bugs/Public/show_bug.cgi?id=14900

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2016-12-14
      • 1970-01-01
      • 2017-01-04
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      相关资源
      最近更新 更多