0

I have a POS web application which currently executes a java applet on page load. I don't want the java applet to be loaded on any computer that doesn't have the display pole for which it was made. The easiest way I can think of to get around this is to have the element disabled and re-enable it via javascript if a variable is "true". The javascript should be given a global variable somehow, which will let it know to activate the applet.

The question therefore is: Is there a way to set a global javascript variable from within the browser or OS? I originally wanted to use system variables but that apparently requires ActiveX controls.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Global variables can be set/changed by anyone. This is not a secure solution. – Evan Davis Jun 30 '12 at 15:52
  • This has practically nothing to do with security. The applet just sends data to a serial port for display. Any PC that is running the web app has "permission" to use the applet; it's just that only ONE of the computers has a pole display to actually make USE of the applet. I only want to know whether or not to load the applet at all (again, not in lieu of security reasons). – SnakeWasTheNameTheyGaveMe Jun 30 '12 at 15:54
  • I think the answer to this is No: browsers are intended to be sandboxed. There is [a question and answer](http://stackoverflow.com/questions/8884347/using-javascript-in-hta-file-to-read-write-from-windows-registry) about reading Registry values which might be useful, but that requires ActiveX to break out of the sandbox. – Andrew Leach Jun 30 '12 at 17:57

3 Answers3

0

See my answer I gave here. It is not exactly what what you wanted, but you might wait in your Applet until a method is called.
Hope it helps!

Community
  • 1
  • 1
11684
  • 7,356
  • 12
  • 48
  • 71
0

From my ..scan of the problem description, given you failed to ask a question I will presume one.

Have a 'hidden applet' the check for the ability to do ..whatever, and on failure, call a script that says/stores 'no'. That script might then communicate with the applet to let it know how to appear, or what to do.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

So a workable solution was to run the applet and have the applet check the name of the computer (http://bytes.com/topic/java/answers/699529-get-host-name-run-applet). After I have that, I had the applet close itself (System.exit(0)) and that pretty much solves any issues of hanging applets over a long period of time. It doesn't solve the issue completely but it's a good place to be in for now.

  • *"`System.exit(0)`) and that pretty much solves any issues of hanging applets"* If the JRE permitted it, it can end not just the applet and page, but close the browser (I have seen it happen)! Calling `System.exit(0)` is not a solution, but a dead-end. – Andrew Thompson Jul 02 '12 at 03:28
  • What do you propose as an alternative to quitting the applet instance? – SnakeWasTheNameTheyGaveMe Jul 02 '12 at 21:45
  • It is not an 'alternative' to `System.exit(n)` but the **correct** way to end an applet is to call [`AppletContext.showDocument(URL)`](http://docs.oracle.com/javase/7/docs/api/java/applet/AppletContext.html#showDocument%28java.net.URL%29) Where the `URL` points to `"ThanksFosUsingOurApplet.html"`. I answered your question, now you answer mine. Have you tried calling `System.exit(n)` in an applet **in a browser** yet? What happened? – Andrew Thompson Jul 03 '12 at 06:55
  • It closed properly. I have the console running whenever java is open and it closed right away which is what I wanted. I also checked the task manager and java closed. I'm using the latest release of Firefox. – SnakeWasTheNameTheyGaveMe Jul 04 '12 at 14:28
  • ..hmm. Next verion of FF, another OS, or another browser and you might see different behavior, especially if the applet is in a page that shares a VM with other applets. You must have knocked the security manager out, BTW, or did you set a custom security manager? – Andrew Thompson Jul 04 '12 at 14:37
  • IE v9 and latest Chrome was just tested and the same result: Java closes. I'm running Windows 7 x64 FWIW. I wouldn't doubt that other pages with Java running would be interrupted but that isn't a problem that needs consideration at the POS. As for the security manager, I'm not sure exactly what you mean. You can see the code I used for the applet at the following URL (sans System.exit(0)). http://stackoverflow.com/questions/7998523/just-trying-to-write-data-to-a-serial-port-from-a-java-applet – SnakeWasTheNameTheyGaveMe Jul 05 '12 at 15:10