Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2014 05:38
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nolanlawson/863e464f3025d7199a1f to your computer and use it in GitHub Desktop.
IndexedDB with Web Workers
<span id="output"></span>
<script src="//"></script>
<script src="main.js"></script>
var worker = new Worker('worker.js');
worker.onmessage = function(event) {
$('#output').text('Output is: ' +;
self.onmessage = function(event) {
var req ='mydb', 1);
req.onupgradeneeded = function (e) {
self.postMessage('successfully upgraded db');
req.onsuccess = function (e) {
self.postMessage('successfully opened db');
req.onerror = function(e) {
Copy link

Nice example. Does "req" only work inside of self.onmessage? I tried putting it all inside a function inside worker.js that self.onmessage calls but it fails to call "onsucess"? any ideas?

  • var req =
  • req..onsuccess = function (e) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment