开发者

HTML 5 Web Worker Example doesn't work in 8.0.552.231

I'm following this example at: http://www.whatwg.org/specs/web-workers/current-work/

page.html

<!DOCTYPE HTML>
<html>
 <head>
  <title>Worker example: One-core computation</title>
 </head>
 <body>
  <p>The highest prime number discovered so far is: <output id="result"></output></p>
  <script>
   var worker = new Worker('worker.js');
   worker.onmessage = function (event) {
     document.getElementById('result').textContent = event.data;
   };
  </script>
 </body>
</html>

worker.js

var n = 1;
search: while (true) {
  n += 1;
  for (var i = 2; i <= Math.sqrt(n); i += 1)
    if (n % i == 0)
     continue search;
  // found a prime!
  postMessage(n);
}

This example works fine in firefox and Safari Version 5.0.2 (6533.18.5) on Mac OSX but doesn't work in chrome. When I debug it, worker.js is not even listed as one of the sources. What is bizarre is that the example page link on the same website works fine in chrome, which is the same code as my local code. But my local code doesn't work in chrome.

When I try to manually run code in Javasc开发者_Go百科ript debugger like this

var w = new Worker('worker.js')

I get an error saying:

Error: SECURITY_ERR: DOM Exception 18

Did anyone else have this experience? Can anyone suggest a solution?

Thanks


Are you viewing this file in the file:/// protocol or over http://? You'll have to serve the page in order for security to process it correctly.

Uncaught Error: SECURITY_ERR: DOM Exception 18 when I try to set a cookie


rxgx is spot on, I've seen this error often. As for a solution, either purchase some cheap shared hosting for development, or, run a web server off your own machine. For Windows, download and install the Apache installer made available from the Apache foundation, and follow the instructions. For Mac OS X, just enable Web Sharing in the Sharing section of System Preferences. For Linux, install an apache or lighttpd package through your package manager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜