O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using a web worker

Let's create a really simple application that gets the user's name and passes it to a web worker. The web worker will return a "hello" message back to the application. The code for this section can be found in Chapter 9/example9.1.

Note

The web workers don't work in some browsers unless you are running them through a web server such as IIS or Apache.

First we create an application with webWorkerApp.html, webWorkerApp.css, and webWorkerApp.js files. We add a text input field to the HTML asking for the user's name and a response section to display the message from the worker:

<div id="main"> <div> <label for="your-name">Please enter your name: </label> <input type="text" id="your-name"/> <button id="submit">Submit</button> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required