javascript - HTML 5 webworkers with multiple arguments -
i got html5 webworkers , want pass multiple arguments worker.
i have in page:
var username = document.getelementbyid("username").value; var server_url = 'localhost'; w.postmessage(username,server_url);
and in worker:
var username = ''; var server_url = ''; onmessage = function (e,f) { username = e.data; server_url = f.data; } console.log(username); console.log(server_url);
and when open page calls worker in browser: uncaught typeerror: failed execute 'postmessage' on 'worker': 2nd argument neither array, nor have indexed properties.
all want have username
, server_url
getting passed worker know in examples hardcoded server_url
, in real script, it's dynamic.
please don't say: change this, that, provide me code can see how should done rather still having figure out myself.
post this:
w.postmessage({user:username,url:server_url})
on message event do:
onmessage = function (e,f) { username = e.data.username; server_url = e.data.url; }
Comments
Post a Comment