下面显示了Web Worker JavaScript文件中错误处理功能的示例,该功能将错误记录到控制台。
<!DOCTYPE HTML> <html> <head> <title>Big for loop</title> <script> var worker = new Worker('bigLoop.js'); worker.onmessage = function (event) { alert("Completed " + event.data + "iterations" ); }; worker.onerror = function (event) { console.log(event.message, event); }; function sayHello(){ alert("Hello sir...." ); } </script> </head> <body> <input type = "button" onclick = "sayHello();" value = "Say Hello"/> </body> </html>