Created
March 16, 2011 21:18
-
-
Save dascgo/873332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Listen for messages coming from main.js | |
onMessage = function onMessage(msg){ | |
// since any number of commands might be passed via the message, | |
// we need to look at the msg.type and process accordingly. | |
if(msg.type == "color_change"){ | |
// in this case, the message is telling us to change the | |
// documents background color. | |
document.body.style.backgroundColor = msg.color; | |
// now that we have done that, tell main.js the task was | |
// completed. | |
postMessage({ | |
"type": "color_change_complete", | |
"status": "ok", | |
"color": msg.color | |
}); | |
}else{ | |
// We've encounted an message that we don't know how to | |
// handle... | |
console.log("unknown message type..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment