Mounting a JavaFX applet from Javascript
Wednesday, 1 July 2009 2:42pm
There's not a whole lot of documentation surrounding the Javascript deployment scripts the new Java Plug-in and JavaFX use (actually I couldn't find any). Luckily if you beautify the minimized code, its not too hard to figure out how things tick.
Out of the box, those scripts use document.write in place, which makes them very problematic if the script is not inlined in the initial HTML page. Trying to call them after the page is loaded will just nuke your document.
Luckily there's a function (javaFxString) in the dtfx.js script that serializes the necessary code to a string which you can use:
var s = javafxString({
codebase: "/s/fwt/javafx/dist/",
archive: "Canvas.jar",
draggable: true,
width: 200,
height: 200,
code: "fan.fwt.Canvas",
name: "Canvas",
id: "app"
});
someElement.innerHTML = s;
This will let you insert the JavaFx applet code anywhere in your DOM. I only tried this in IE8 so far (since this is a workaround for IE-only). But I assume this should work in all browsers.