forked from skjApp/HTML5-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebWorkerBasic.htm
57 lines (43 loc) · 1.07 KB
/
WebWorkerBasic.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<title>Example - Web Worker Basic</title>
</head>
<body>
<p>
Table of 2 : <div id="result"></div>
</p>
<button onclick="startWorker()">Start Web Worker</button>
<button onclick="stopWorker()">Stop Web Worker</button>
<br/>
<br/>
<script>
var w;
function startWorker()
{
if(typeof(Worker) !== "undefined") // Checking whether Web Workers are supported or not in the browser
{
if(w == undefined)
{
w = new Worker("WebWorkerBasic.js");
}
// Setting a meesage processing method
w.onmessage = receiveMessage ;
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support Web Workers";
}
}
function stopWorker()
{
w.terminate(); // Terminating the worker
w = undefined ;
}
function receiveMessage(event)
{
document.getElementById("result").innerHTML = event.data;
};
</script>
</body>
</html>