"HTML5" Web Workers

Source: Internet
Author: User

What is a Web Worker?

When you execute a script in an HTML page, the state of the page is not responsive until the script is complete.

Web Worker is a JavaScript running in the background, independent of other scripts, without affecting the performance of the page. You can continue to do anything you want to do: Click, select Content, and so on, while the Web worker runs in the background.

Counter:

<! DOCTYPE html>varW;functionStartworker () {if(typeof(Worker)!== "undefined")  {//The following code detects if a worker exists, and if it does not exist-it creates a new Web worker object and then runs the code in "Demo_workers.js":  if(typeof(w) = = "Undefined") {W=NewWorker ("/example/html5/demo_workers.js"); }//Add a "onmessage" event listener to the Web worker:W.onmessage =function(event) {document.getElementById ("Result"). innerhtml=Event.data;  }; }Else{document.getElementById ("Result"). Innerhtml= "Sorry, your browser does not support Web Workers ..."; }}functionStopworker () {//To terminate the Web worker and release the browser/computer resources, use the Terminate () method:w.terminate ();}</script></body>

"HTML5" Web Workers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.