Is there any way for me to make values generated by a separate program available to JavaScript?
I’m fairly new to web design and JavaScript, so I’m not really sure if it is possible to do what I want at all. I know some of this is intentionally made difficult to do (prevented?) due to security issues. I don’t need an actual written out solution so much as a confirmation that is or isn’t possible, and maybe the appropriate API/function sets that would be used for it.
I want to have a web page which uses third party JavaScript API functions based on values being generated in a separate program on the device accessing the website, which is talking to external devices. I want this to be an ongoing process though; once the webpage is open it should continue to monitor the values and update the calls as appropriate.
Some sort of direct interaction would be preferable (is there a way to pass in a callback function or something?), but I haven’t seen anything so far which looks like it could do that.
Is it possible to do something like write the values to an XML file on the program side and have a loop which repeatedly re-reads the file out on the webpage side? I don’t know that this would be fast enough for what I want.
I’m not worried about compatibility with a large range of browsers or anything, so even a solution which uses something like a rarely supported HTML5 syntax would be fine as long as I can get one browser that it works on.
This is actually a very, very good question. Some people may have skimmed it and to them it would look like lots of other newbie-misunderstands-the-web type questions. But this is actually different:
The bolded part is what makes this different.
Yes it’s possible. It’s how Flash and Java plugins can have access to your webcam and microphone. But it’s not easy.
Firstly, this is not your usual server-based interaction (if it was, it would be much simpler and lots of web devs would be rightfully annoyed at yet another newbie asking such questions). You basically want your web app to have access to hardware on the user’s machine.
Good, that makes it a bit simpler. Because the web APIs don’t handle this sort of thing at all. You need low level access to the browser.
You basically have 2 options:
If Flash or Java supports accessing the hardware you’re trying to access then you can try writing an applet in either Flash or Java. Of the two, Java is slightly more friendly to programmers wanting to do low level, non-standard stuff. But flash is often more friendly to users (for some reason, Java applets to this day tend to be huge and take a long time to load).
If you can’t do what you want in Flash or Java then you really only have one other option: write a browser plugin. For this there are two options (note: I’ve never done this before so I’m only going by what I’ve read). First is you can develop a plugin based on the old Netscape Plugin API. Google around to learn more about it. For IE on windows you have a second option of developing an ActiveX plugin. you can try to google around for that as well.
A bit of googling led me to Firebreath which is a cross-browser plugin framework that can compile to both NPAPI and ActiveX.
Oh, there is a third option. For Chrome and Firefox you can write javascript based plugins. Though like ActiveX on IE, the plugins won’t be cross-browser compatible. I’m not even sure if the javascript plugin API can access really low level hardware.
What you’re trying to do is interesting. Not many people have done it. But it’s doable. Good luck.