Web Worker Case

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.

Detect if the browser supports Web Worker

Before you create a web worker, detect whether the user's browser supports it:

if (typeof (Worker)!== "undefined")
{
Yes! WEB Worker Support!
// some code .....
}
Else
{
I'm sorry! Web Worker does not support
}



<! DOCTYPE html> <meta charset="Utf-8"> <title> Rookie Tutorial (runoob.com) </title> "result"></output></p><button onclick="Startworker ()"> Start work </button> <button onclick="Stopworker ()"> Stop Working </button><p><strong> note:</strong> Internet Explorer9And earlier versions of IE browsers do not support Web workers.</p><script>varw;function Startworker () {if(typeof(Worker)!=="undefined") { if(typeof(w) = ="undefined") {W=NewWorker ("Demo_workers.js"); } w.onmessage= function (Event) {document.getElementById ("result"). InnerHTML =Event. Data; }; } Else{document.getElementById ("result"). InnerHTML ="Sorry, your browser does not support Web Workers ..."; }}function Stopworker () {w.terminate (); W=undefined;}</script></body>

Web Worker Case

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.