Window.alert on the working branch

If I put window.alert on the webmaster client, the background worker stops working. Why is this so?

i.e. Defiant:

var worker = new Worker("worker.js");
// Watch for messages from the worker
worker.onmessage = function(e){
  // The message from the client:
  e.data
};
worker.postMessage("start");

      

Client (worker.js)

onmessage = function(e){
  if ( e.data === "start" ) {
    // Do some computation
    done()
  }
};

function done(){
  alert('don');  // ===> This kills the worker.
  // Send back the results to the parent page
  postMessage("done");
}

      

+2


source to share


3 answers


You noticed that the warning hangs on the javascript engine until the user types OK.

If you don't want it to freeze, don't use warnings.

For debugging with firebug:

console.log("bla bla bla");

      



For non-blocking pop-ups:

create a hidden div with ok button. When the popup appears. Make the div visible. When the user clicks "ok", hide it.

I would advise you not to use pop-ups. It also disrupts the "workflow" (which means user concentration) of the user behind the screen :)

0


source


The web user has access to window.alert ... I know that web workers cannot access the home.

at the worker, why not do



if (window && window.alert) {
   // do your normal thing
}
else {
   postMessage("no support for this");
}

      

+2


source


Website workers allow JavaScript code to run in the background. Web workers cannot call alert () or confirm () functions.

0


source







All Articles