Javascript无法解析相对于当前脚本的工作路径 [英] Javascript not resolving worker path relative to current script
问题描述
我在 http://localhost/js/foo.js
上有一个脚本,它需要从文件 http生成一个Web Worker: //localhost/js/fooWorker.js
。我以为我可以做这样的事情:
I have a script at http://localhost/js/foo.js
which needs to spawn a Web Worker from the file http://localhost/js/fooWorker.js
. I assumed I could just do something like this:
var worker = new Worker('fooWorker.js')
但是,这会导致404错误,因为浏览器找不到 http:// localhost /fooWorker.js
。我的印象是工作路径相对于产生工作者的脚本被解析了,所以我不应该只能在同一目录中指定另一个.js文件的名称而不必提供绝对路径?我做错了吗?
However, this results in a 404 error, as the browser cannot find http://localhost/fooWorker.js
. I was under the impression that worker paths were resolved relative to the script spawning the worker, so shouldn't I just be able to specify the name of another .js file in the same directory without having to provide an absolute path? Am I doing something wrong?
推荐答案
来自http://www.w3.org/TR/workers/ :
当工人(scriptURL)调用构造函数,用户代理必须
运行以下步骤:
When the Worker(scriptURL) constructor is invoked, the user agent must run the following steps:
- 解析相对于条目的scriptURL参数调用方法时脚本的基础
URL。
这篇关于Javascript无法解析相对于当前脚本的工作路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!