20.11.2017 Views

My HTML 5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HTML</strong>5<br />

Handle Server-Sent Events<br />

Let us modify our web application to handle server-sent events. Following is the final<br />

example.<br />

<br />

<br />

<br />

<br />

document.getElementsByTagName("eventsource")[0].addEventListener("server-time",<br />

eventHandler, false);<br />

function eventHandler(event)<br />

{<br />

// Alert time sent by the server<br />

document.querySelector('#ticker').inner<strong>HTML</strong> = event.data;<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

[TIME]<br />

<br />

<br />

<br />

Before testing Server-Sent events, I would suggest that you make sure your web browser<br />

supports this concept.<br />

60

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!