Skip to content

Instantly share code, notes, and snippets.

@dascgo
Created March 16, 2011 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dascgo/873332 to your computer and use it in GitHub Desktop.
Save dascgo/873332 to your computer and use it in GitHub Desktop.
// 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