jquery - Web Worker Javascript cannot find functions in other javascript files -
i have html file this:
<html> <head> <title>world aviation</title> <script language="javascript" src="./jquery-min.js"> </script> <script language="javascript" src="./jsdraw2d.js"> </script> <script language="javascript" src="./script.js"> </script> </head> <body> <input onclick="startanimbackground();" type="button" value="start"/> <script language="javascript"> initairports(); initroutes(); var w; function startanimbackground() { if(typeof(worker) !== "undefined") { if(typeof(w) == "undefined") { w = new worker("start_script.js"); } } else { startanimation(); } } </script> </body> </html>
the file "start_script.js" contains 1 line calls startanimation() function. function located in "script.js"
my problem is: browser supports web-workers, creates web-worker , loads file "start_script.js", fails call function "startanimation()" indicating cannot find function. function located in script.js included in head section. so, conclusion can draw web-worker js files have different scope , not able include 3 javascript files specified in head section. should make work? thanks.
web workers don't share functions, variables, or scripts main script.
to load dependencies, call importscripts()
in worker.
to allow web worker interact or affect main script or dom, have use message passing , have main script listen for, interpret, , act on messages.
see: https://developer.mozilla.org/en-us/docs/web/guide/performance/using_web_workers
Comments
Post a Comment