close() 方法在 EventSource interface closes the connection, if one is made, and sets the EventSource.readyState 属性到 2 (closed).

注意 : If the connection is already closed, the method does nothing.

句法

eventSource.close();
					

参数

None.

返回值

Void.

范例

var button = document.querySelector('button');
var evtSource = new EventSource('sse.php');
button.onclick = function() {
  console.log('Connection closed');
  evtSource.close();
}
					

注意 : You can find a full example on GitHub — see Simple SSE demo using PHP.

规范

规范 状态 注释
HTML 实时标准
The definition of 'close()' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
close Chrome 6 Edge 79 Firefox 6 IE 不支持 No Opera Yes Safari 5 WebView Android Yes Chrome Android 18 Firefox Android 45 Opera Android 12 Safari iOS 5 Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: