Search in sources :

Example 6 with JsObject

use of com.teamdev.jxbrowser.js.JsObject in project JxBrowser-Examples by TeamDev-IP.

the class JsAccessibleMethod method main.

public static void main(String[] args) {
    try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
        Browser browser = engine.newBrowser();
        browser.mainFrame().ifPresent(frame -> {
            JsObject jsObject = frame.executeJavaScript("window");
            if (jsObject != null) {
                // Inject Java object into JavaScript and associate it
                // with the "window.java" JavaScript property.
                jsObject.putProperty("java", new JavaObject());
            }
            // Call the annotated public method of the injected Java object from JS.
            frame.executeJavaScript("window.java.sayHello()");
        });
    }
}
Also used : JsObject(com.teamdev.jxbrowser.js.JsObject) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

JsObject (com.teamdev.jxbrowser.js.JsObject)6 Browser (com.teamdev.jxbrowser.browser.Browser)4 Engine (com.teamdev.jxbrowser.engine.Engine)4 Frame (com.teamdev.jxbrowser.frame.Frame)3 C8oBrowser (com.twinsoft.convertigo.eclipse.swt.C8oBrowser)2 DatabaseObjectFoundException (com.twinsoft.convertigo.engine.DatabaseObjectFoundException)2 File (java.io.File)2 JSONException (org.codehaus.jettison.json.JSONException)2 CoreException (org.eclipse.core.runtime.CoreException)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 PartInitException (org.eclipse.ui.PartInitException)2 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)1 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)1 JFrame (javax.swing.JFrame)1