Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:03:15+00:00 2026-06-17T05:03:15+00:00

In a simple HTML5 web worker project, I have defined a web worker which

  • 0

In a simple HTML5 web worker project, I have defined a web worker which exchanges messages using HTML5 messaging API. There is a source of confusion for me here due to the fact that we have defined two .onmessage handlers (callback functions), one in the main script and the other one in the worker.js:
index.html:

<!DOCTYPE html>
<html>
<body>
<script>
var worker = new Worker("worker.js");
worker.onmessage = function(event) {
    alert("Reply from index.html:"+event.data);
}
worker.postMessage("message 3,");
</script>
</body>
</html>

worker.js:

this.onmessage = function(event) {
    postMessage("message 0,"+event.data);
} 
postMessage("message 1,");

one thing that i don’t get is the order of messages being displayed!
it first displays this:
enter image description here
and then displays this
enter image description here

But why? I am confused how and when these handlers were called? first the worker.postMessage(“message 3,”); triggers the worker.postMessage(“message 3,”); in worker.js and postMessage(“message 0,”+event.data); in returns triggers the worker.onmessage = function(event) in the main script! then at the very end the postMessage(“message 1,”); from the worker.js triggers the onmessage of the main script(index.html). Can we say we are any postMessage call on a worker triggers the onmessage function of other web workers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:03:16+00:00Added an answer on June 17, 2026 at 5:03 am

    You might be confusing the Web Worker implementation with js methods that you may pass the objects as a function. WEB WORKERS in HTML5 are are bringing the THREADING TO JAVASCRIPT.

    Reason seems to be in the append event of ‘.onmessage’ and your worker.js starts with posted expression ‘postMessage(“message 0,”+event.data);’ . The message 0 comes first because of that reason.

    A good introductory tutorial like the following one should address your concerns – THE BASICS OF WEB WORKERS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello every one I have wrote a simple code in html5 in which I
I'm trying to create a simple web project using Tomcat in Java. In the
I'm using this code for my web assignment: http://csstechniques.blogspot.sg/2007/05/super-simple-css-bars.html But how do I show
I have a very simple HTML5 game that works as expected from a regular
Does anyone know of a simple HTML5/CSS3 framework which applies a minimum of formatting
I'm drawing simple text in HTML5 canvas using this: context.fillStyle = #FF0000 context.font =
I'm making a simple app using the HTML5 <canvas> tag and compile the code
I just create a new MVC 4 Web API project, and create a new
I have worked in a web project with a heavy part on JavaScript, and
I'm using Service Stack for a simple web application. In this app i need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.