forked from greenido/Web-Workers-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalStorage-worker-try.html
46 lines (39 loc) · 1.21 KB
/
localStorage-worker-try.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Web Worker: Inline worker with LocalStorage example</title>
<meta name="author" content="Ido Green">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<style>
#status {
background: lightGreen;
border-radius: 15px;
padding: 15px;
}
</style>
<body>
<h1>Web Worker: Inline worker with LocalStorage example</h1>
<div id="status"></div>
<script id="worker1" type="javascript/worker">
self.onmessage = function(e) {
postMessage("<h3>Worker: Started</h3>");
localStorage.setItem("key", "myValue");
postMessage("<h3>Worker: Done</h3>");
}
</script>
<script>
function status(msg) {
$("#status").append(msg);
}
var bb = new (window.BlobBuilder || window.WebKitBlobBuilder)(); //new BlobBuilder();
bb.append(document.querySelector('#worker1').textContent);
var worker = new Worker(window.webkitURL.createObjectURL(bb.getBlob()));
worker.onmessage = function(e) {
status(e.data);
}
worker.postMessage(); // Start the worker
</script>
</body>
</html>