我可以从绝对URL加载一个web worker脚本吗? [英] Can I load a web worker script from an absolute URL?

查看:530
本文介绍了我可以从绝对URL加载一个web worker脚本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

在我的Firebug控制台中,出现如下错误:


无法加载脚本:
http: //example.com/js/worker.js
(nsresult = 0x805303f4)


网络工作者的用法我已经看到从相对路径加载脚本。我试过这样的东西,它工作得很好:

  var myWorker = new Worker(worker.js); 

但是如果我需要加载一个不在相对位置的工作脚本呢?我已经广泛搜索,我没有看到这个问题在任何地方解决。



我应该补充一点,我试图在Firefox 3.5中做到这一点。

解决方案

对于那些不知道的,这里是Web Worker的规范:
http://www.whatwg.org/specs/web-workers/current-work/

John Resig的帖子:
http://ejohn.org/blog/web-workers/



一般而言,Javascript不能访问javascript文件的url以外的任何内容来自。

我相信这部分规范的意思是,来自: http://www.w3.org/TR/workers/

  4.2工作人员的基本URL和起源

工作中运行的脚本的起源和有效脚本起源ers是工作人员的位置属性所表示的绝对URL的来源。

这篇文章有一个关于在你的情况下应该抛出什么错误的声明:
http://canvex.lazyilluminati。 com/misc/cgi/issues.cgi/message/%3Cop.u0ppu4lpidj3kv@zcorpandell.linkoping.osa%3E


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

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

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

Failed to load script: http://example.com/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.

解决方案

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

And a post by John Resig: http://ejohn.org/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.org/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.com/misc/cgi/issues.cgi/message/%3Cop.u0ppu4lpidj3kv@zcorpandell.linkoping.osa%3E

这篇关于我可以从绝对URL加载一个web worker脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆