Reputation: 33817
Is it possible to have a Java applet (not JavaScript) that opens an URL in an iFrame in the browser? Something equivalent this in jQuery:
$('<frame />').attr('src', 'http://example.com').attachTo('body')
Upvotes: 1
Views: 3256
Reputation: 11256
Java applets can call javascript methods. This way you can achieve what you like, and this allows you to do what you are asking for.
In order to do this, you will need to explicitly gice the applet permission to access scripts on a page. This is done for instance by adding the following line to an applets OBJECT tag.
<PARAM NAME="MAYSCRIPT" VALUE="true">
For examples of how to do this with the old APPLET tag or new EMBED tag see here: http://docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/java_js.html
After doing that you access scripts from an applet via JSObject as shown in the following example:
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
public void init() {
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
JSObject loc = (JSObject) doc.getMember("location");
String s = (String) loc.getMember("href"); // document.location.href
win.call("f", null); // Call f() in HTML page
}
}
Upvotes: 2
Reputation: 31813
Yes.
http://docs.oracle.com/javase/tutorial/deployment/applet/invokingJavaScriptFromApplet.html
Upvotes: 2