最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can I load a web worker script from an absolute URL? - Stack Overflow

programmeradmin4浏览0评论

I haven't been able to get something like this to work:

var myWorker = new Worker(".js");

In my Firebug console, I get an error like this:

Failed to load script: .js (nsresult = 0x805303f4)

Every example of web worker usage I've seen loads a script from a relative path. I tried something like this, and it works just fine:

var myWorker = new Worker("worker.js");

But what if I need to load a worker script that's not at a relative location? I've googled extensively, and I haven't seen this issue addressed anywhere.

I should add that I'm attempting to do this in Firefox 3.5.

I haven't been able to get something like this to work:

var myWorker = new Worker("http://example./js/worker.js");

In my Firebug console, I get an error like this:

Failed to load script: http://example./js/worker.js (nsresult = 0x805303f4)

Every example of web worker usage I've seen loads a script from a relative path. I tried something like this, and it works just fine:

var myWorker = new Worker("worker.js");

But what if I need to load a worker script that's not at a relative location? I've googled extensively, and I haven't seen this issue addressed anywhere.

I should add that I'm attempting to do this in Firefox 3.5.

Share Improve this question asked Oct 11, 2009 at 1:48 mattblodgettmattblodgett 3051 gold badge5 silver badges11 bronze badges 2
  • Hi there, can you elaborate and tell us more about the Worker class? is this not working in FF3.5 only or all browsers? – mauris Commented Oct 11, 2009 at 1:52
  • Here's the official Mozilla documentation on the Worker class: developer.mozilla/En/DOM/Worker Firefox is the only browser I care about. I eventually want to use web workers in a Greasemonkey script I'm working on. – mattblodgett Commented Oct 11, 2009 at 2:04
Add a ment  | 

3 Answers 3

Reset to default 9

For those that don't know, here is the spec for Web Worker: http://www.whatwg/specs/web-workers/current-work/

And a post by John Resig: http://ejohn/blog/web-workers/

Javascript, generally, can't access anything outside of the url that the javascript file came from.

I believe that is what this part of the spec means, from: http://www.w3/TR/workers/

4.2 Base URLs and origins of workers

Both the origin and effective script origin of scripts running in workers are the origin of the absolute URL given in that the worker's location attribute represents.

This post has a statement about what error should be thrown in your situation: http://canvex.lazyilluminati./misc/cgi/issues.cgi/message/%[email protected]%3E

According to the Web Worker draft specification, workers must be hosted at the same domain as the "first script", that is, the script that is creating the worker. The URL of the first script is what the worker URL is resolved against.

Not to mention...

Just about anytime you have a Cross-Origin Restriction Policy, there's no counterpoise to the file system (file://path/to/file.ext) - Meaning, the file protocol triggers handling for this policy.

This goes for "dirty images" in the Canvas API as well.

Hope this helps =]

发布评论

评论列表(0)

  1. 暂无评论