Current situation
We are currently using the applet to perform some operations, after which it redirects the current page. At its core, you could see the applet as follows:
public class ExampleApplet extends Applet { @Override public void init() { Button redirect = new Button("Redirect"); this.add(redirect); final String target = this.getParameter("targetPage"); redirect.addActionListener((ActionEvent e) -> { try { getAppletContext().showDocument(new URL(target), "_parent"); } catch (MalformedURLException ex) {} }); } }
when the applet is called in the simplest way:
<applet code="com.example.applet.ExampleApplet.class" archive="${appletUrl}" width="100" height="30"> <param name="targetPage" value="http://localhost:8080/applet/"/> </applet><br/><br/>
where ${appletUrl} returns the location of the JAR applet.
So, an applet is nothing more than a simple button that calls getAppletContext().showDocument(new URL(target), "_parent"); to refresh the current page. This has done its job correctly for a long time. Now here is the question.
Migration
As many people know, Chrome does not support Applet s. Some time was delayed since IE and FireFox still supported them. At the end of 2016, they will also no longer support them. Therefore, we decided to port the applet using JWS and JNLP .
Migrating this simple example redirect button will give the following html snippet and JNLP file:
<a href="${jnlpUrl}">Launch JNLP</a>
${jnlpUrl} returns the location in the JNLP file, which:
<?xml version="1.0" encoding="utf-8"?> <jnlp spec="1.0+" codebase="http://localhost:8080/applet/assets/1.0-SNAPSHOT-DEV/app/assets/" href="jnlp/example.jnlp"> <security> <all-permissions/> </security> <resources> <j2se version="1.5+" initial-heap-size="32m" max-heap-size="128m" /> <property name="jnlp.versionEnabled" value="false"/> <jar href="applets/ExampleApplet.jar" main="true"/> </resources> <applet-desc name="code" main-class="com.example.applet.ExampleApplet.class" width="30" height="30" > <param name="targetPage" value="http://localhost:8080/applet/"/> </applet-desc> </jnlp>
So far so good, the same applet is successfully deployed as a JWS application. Allow it to be used from any browser, as it runs outside of it. Which is also a problem.
Problem
String getAppletContext().showDocument(new URL(target), "_parent"); still redirects, but uses the default browser as indicated in the migration documentation .
For AppletContext.showDocument (URL url, String target), the target argument will be ignored by Java Web Start technology.
Like AppletContext.showDocument, Java Web Start applications can use the HTML page using the default web browser using the BasicService.showDocument API.
So, if my default browser is FireFox, but I happen to be viewing this JWS-enabled applet in IE / Chrome, a new tab will open in FireFox. This is a problem, as I have information (e.g. login) stored in the original browser!
conclusions
Since the application runs outside the browser, I am having problems communicating with the original browser. I can not use JavaScript , because it does not run in the browser. I cannot determine a system-independent way to open a tab in the source browser. I also thought about WebSockets , as they can allow direct communication, but from what I read it is pretty high-level and requires a server, not a simple applet.
Is there a possibility of communication between the original browser (for example, websockets and parameters) or the transfer of a session from one browser to another when the applet opens a new window?