W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>调用 onmessage 事件的文档的 URL:</p> <div id="myDIV"></div> <p><b>注释:</b>Internet Explorer 不支持 Server-Sent 事件。</p> <script> if(typeof(EventSource) !== "undefined") { var source = new EventSource("/html/demo_sse.php"); source.onmessage = function(event) { document.getElementById("myDIV").innerHTML = event.origin; }; } else { document.getElementById("myDIV").innerHTML = "Sorry, your browser does not support server-sent events..."; } </script> </body> </html>