// After the Applet Text has been updated JSObject win = null; try { win = (JSObject) JSObject.getWindow(Applet.this); win.call("updateText", new Object[] { textBox.getText() }); } catch (Exception ex) { // oops }
String callbackFunction; public void RegisterCallback(String functionName) { callbackFunction = functionName; } void UseCallbackFunction() { if (callbackFunction == null) return; JSObject win = (JSObject) JSObject.getWindow(this); win.call(callbackFunction, null); }
private String getDocumentCookies() { JSObject window = (JSObject)JSObject.getWindow(this); return window.call ("getDocumentCookies", new String[0]); }
public void DoProcessing(final Object callbacks) { //do processing.... JSObject w = JSObject.getWindow(this); //Call our named callback, note how we pass the callbacks parameter straight //back out again - it will be unchanged in javascript. w.call("ProcessingCallback", new Object[]{successful, output, callbacks}); }
public void sendToJs() { String name = getSystemUsername(); try { JSObject window = JSObject.getWindow(this); window.call("updateServer", new Object[] {name}); } catch (JSException jse) { jse.printStackTrace(); } }
JSObject window = JSObject.getWindow(this); // invoke JavaScript function String result = "<table><tr><th>Column1</th><th>Column2</th></tr><tr><td>" + field1 + "</td><td>" + field2 + "</td></tr></table>"; window.call("writeResult", new Object[] {result});
public class MyClass extends JApplet { public void init() { JSObject window = JSObject.getWindow(this); Object[] args = new String[] { "bar" }; window.call("foo", args); } }
// same code as above up to eval call engine.eval("function doit(p) { list.add(p); return true; }", context); // Instead of invokeFunction(), just get and call function manually JSObject func = (JSObject)scope.get("doit"); func.call(null, "Hello!!!"); // like a "static" call, no 'this' value System.out.println(list); // prints: [Hello!!!]
JSObject obj = (JSObject)ctx.get("{ add : function(a,b){ return a+b;}}"); Double result = (Double)obj.call("add", new Object[]{new Integer(1), new Integer(3)} ); // Result should be 4.0
webEngine.getLoadWorker().stateProperty().addListener( new ChangeListener<Worker.State>() { @Override public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) { if (newValue == Worker.State.SUCCEEDED) { JSObject windowObject = (JSObject) webEngine.executeScript("window"); windowObject.setMember("Debug", debug); // insert object windowObject.call("ready"); // execute callback } } } );
private int getArrayLength(Object val) throws JSException { int length = ((Number) arraySizeFn().call("array", val, null)).intValue(); return length; }
final JSObject convertArrays(Object[] arr) { for (int i = 0; i < arr.length; i++) { if (arr[i] instanceof Object[]) { arr[i] = convertArrays((Object[]) arr[i]); } } final JSObject wrapArr = (JSObject)wrapArrFn().call("array", arr); // NOI18N return wrapArr; }
private Object[] toArray(int length, Object val) throws JSException { Object[] arr = new Object[length]; arraySizeFn().call("array", val, arr); checkArray(arr); return arr; }
ScriptContext context = new SimpleScriptContext(); context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE); //Exception handling omitted for brevity //Evaluate the compiled runtime in our new context compiledRuntime.eval(context); //Evaluate the source in the same context engine.eval(source, context); //Call a function JSObject jsObject = (JSObject) context.getAttribute(function, ScriptContext.ENGINE_SCOPE); jsObject.call(null, args);
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 } }
private List byTagName(final String tagName) { return AppThread.exec(contextItem.statusCode, () -> { validate(false); if (node != null) { return asList(parseScriptResult( node.call("getElementsByTagName", new Object[] { tagName }))); } return new ArrayList<ElementServer>(); }); }
private static void validate(JSObject node, ContextItem contextItem) { if (node == null) { throw new NoSuchElementException("Element not found or does not exist."); } JSObject doc = node instanceof Document ? node : (JSObject) ((Node) node).getOwnerDocument(); if (!contextItem.containsFrame(doc)) { throw new StaleElementReferenceException("The page containing the element no longer exists."); } if (!(Boolean) doc.call("contains", node)) { throw new StaleElementReferenceException("The element no longer exists within the page."); } }
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 } }
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 } }
public int Do() { JSObject win = (JSObject) JSObject.getWindow(this); JSObject doc = (JSObject) win.getMember("document"); JSObject fun = (JSObject) win.getMember("DumberTest"); JSObject loc = (JSObject) doc.getMember("location"); String href = (String) loc.getMember("href"); String[] arguments = { href, fun.toString() }; win.call("DumbTest", arguments); return fun.toString().length(); }