onmessage=script - メッセージ受信時のハンドラ
属性
<タグ名 onmessage=script>説明
postMessage() によるメッセージ受信時のハンドラを指定します。
サンプル
Google Chrome や Opera では、ローカルファイルでは動作しません。http: か https: で始まるURLでアクセスしてください。
test.html
<!DOCTYPE html> <head> <title>WebMessage TEST</title> <script> function init() { var worker = new Worker('test.js'); worker.onmessage = function(event) { document.getElementById('result').innerHTML = event.data; }; } </script> </head> <body onload="init()"> <div id="result"> </div> </body> </html>
test.js
var count = 0; setInterval(function() { postMessage('hoge' + count++); }, 1000);
Copyright (C) 2015-2017 杜甫々
初版:2015年1月2日 最終更新:2017年12月31日
https://www.tohoho-web.com/html/attr/onmessage.htm