- From: poot <cvsmail@w3.org>
- Date: Thu, 25 Mar 2010 17:18:30 +0900 (JST)
- To: public-html-diffs@w3.org
workers; hixie: I am incompetent at this editing thing. (whatwg r4867)
http://dev.w3.org/cvsweb/html5/workers/Overview.html?r1=1.239&r2=1.240&f=h
http://html5.org/tools/web-apps-tracker?from=4866&to=4867
===================================================================
RCS file: /sources/public/html5/workers/Overview.html,v
retrieving revision 1.239
retrieving revision 1.240
diff -u -d -r1.239 -r1.240
--- Overview.html 25 Mar 2010 07:56:32 -0000 1.239
+++ Overview.html 25 Mar 2010 08:18:18 -0000 1.240
@@ -486,18 +486,24 @@
second, a message is sent <em>to</em> the worker, causing the worker
to send another message in return. Received messages are again
displayed in a log.<p>Here is the HTML page:<pre><!DOCTYPE HTML>
-<title>Shared workers: demo 1</title>
+<title>Shared workers: demo 2</title>
<pre id="log">Log:</pre>
<script>
var worker = new SharedWorker('test.js');
var log = document.getElementById('log');
- worker.port.onmessage = function(e) { // note: not worker.onmessage!
+ worker.port.addEventListener('message', function(e) {
log.textContent += '\n' + e.data;
- }
+ }, false);
+ worker.port.start(); // note: need this when using addEventListener
+ worker.port.postMessage('ping');
</script>
</pre><p>Here is the JavaScript worker:<pre>onconnect = function(e) {
var port = e.ports[0];
port.postMessage('Hello World!');
+ port.onmessage = function(e) {
+ port.postMessage('pong'); // not e.ports[0].postMessage!
+ // e.target.postMessage('pong'); would work also
+ }
}
</pre><hr><p>Finally, the example is extended to show how two pages can
connect to the same worker; in this case, the second page is merely
Received on Thursday, 25 March 2010 08:18:58 UTC