Sunday, February 22, 2015

Belajar HTML5 Web Workers bag. 2

Nah, berikut ini adalah contoh komplit dari web workers untuk file html:
<!DOCTYPE html>
<html>
<body>

<p>Count numbers: <output id=”result”></output></p>
<button onclick=”startWorker()”>Start Worker</button>
<button onclick=”stopWorker()”>Stop Worker</button>
<br /><br />

<script>
var w;

function startWorker()
{
if(typeof(Worker)!==”undefined”)
{
if(typeof(w)==”undefined”)
{
w=new Worker(“demo_workers.js”);
}
w.onmessage = function (event) {
document.getElementById(“result”).innerHTML=event.data;
};
}
else
{
document.getElementById(“result”).innerHTML=”Sorry, your browser does not support Web Workers…”;
}
}

function stopWorker()
{
w.terminate();
}
</script>

</body>
</html>

0 comments:

Post a Comment

 

© Copyright 2010 oleh HariZ| Powered By : Blogger