We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

这篇翻译不完整。请帮忙从英语翻译这篇文章

 

EventSource 的方法close()用于关闭当前的连接,如果调用了此方法,则会将EventSource.readyState这个属性值设置为 2 (closed)

Note: 如果连接已经被关闭,此方法不会做任何事情

语法

eventSource.close();

参数

None.

返回值

Void.

例子

var button = document.querySelector('button');
var evtSource = new EventSource('sse.php');

button.onclick = function() {
  console.log('Connection closed');
  evtSource.close();
}

Note: 你可以在Github上查看这整个例子: Simple SSE demo using PHP.

规范

Specification Status Comment
HTML Living Standard
close()
Living Standard Initial definition

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
EventSource support 6 未实现 6.0 (6.0) 未实现 (Yes) 5
Available in shared and dedicated workers[1] (Yes) 未实现 53.0 (53.0) 未实现 (Yes) (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
EventSource support 4.4 45 未实现 12 4.1
Available in shared and dedicated workers[1] (Yes) 53.0 (53.0) 未实现 (Yes) (Yes)

[1] But not service workers as yet.

相关链接

文档标签和贡献者

此页面的贡献者: Char-Ten
最后编辑者: Char-Ten,