admin管理员组

文章数量:1279090

I'm trying to create a HTML5 Web Worker in phonegap, but phonegap doesn't allow me to load a local javascript file at runtime. I get the following error:

var web_worker=new Worker('socket-worker.js')
undefined
file://socket-worker.jsFailed to load resource: The requested URL was not found on this server.

Does anyone have a good suggestion on how I can work around this, and get the worker running?

Thanks!

I'm trying to create a HTML5 Web Worker in phonegap, but phonegap doesn't allow me to load a local javascript file at runtime. I get the following error:

var web_worker=new Worker('socket-worker.js')
undefined
file://socket-worker.jsFailed to load resource: The requested URL was not found on this server.

Does anyone have a good suggestion on how I can work around this, and get the worker running?

Thanks!

Share Improve this question asked Apr 19, 2013 at 16:09 asprotteasprotte 1,1011 gold badge9 silver badges12 bronze badges 3
  • 1 there's absolutely no problem with PhoneGap loading files at runtime. Check your filepath, try with absolute path once. – SHANK Commented Apr 20, 2013 at 10:53
  • @asprotte - were you able to use webworkers from phonegap? – murtaza52 Commented Jun 14, 2013 at 7:07
  • Thank you SHANK. You were right, the problem was not with loading the file. @murtaza52 yes, the problem wasn't actually with the socket-worker.js file but due to the method i was importing the js library socket.io in my socket-worker.js using importScripts(). Instead of importing the socket.io script locally I had to load in it with an http request: importScripts('someaddress/socket.io.js') – asprotte Commented Jun 17, 2013 at 13:23
Add a ment  | 

2 Answers 2

Reset to default 9

Haven't tried this yet but I believe we can run it using blob url. See it here ( http://www.html5rocks./en/tutorials/workers/basics/#toc-inlineworkers-bloburis )

Update: I've tried this already and it worked. :)

As per my knowledge Web Workers never works on local directory

file://

it works on server side. For example instead of placing files at "file://" so the path should be

***> http://localhost/ or***
***> http://server_ip_address***

Hence Phonegap consists of HTML and Javascript which are at device directory hence web workers are not supported in Phonegap.

本文标签: javascriptUsing web workers in phonegapStack Overflow