Servis-Rhino 4211B Betriebsanweisung Seite 279

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 298
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 278
Associated with a WebView component is a parallel component called the WebEngine. It is the
WebEngine that actually implements the browser and the WebView becomes the face of it. The
WebEngine associated with a WebView can be obtained through the getEngine() method.
To load a page into the browser, one can call the WebEngine method called load() passing in a
String URL. If the HTML we wish to load within the browser is local (i.e. a simple String) then we
use the loadContent() method. This method also wants a contentType parameter which is
the MIME type of the content. Typically this is "text/html".
Because a page load in the browser occurs asynchronously, we may wish to know when the page is
loaded. We can do this using the getLoadWorker() method which returns a Worker instance.
Through this we can be notified of the worker's state changes.
Should we need to set cookies on a web site, the following may work:
WebView webView = new WebView();
URI uri = URI.create("http://mysite.com");
Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
headers.put("Set-Cookie", Arrays.asList("name=value"));
java.net.CookieHandler.getDefault().put(uri, headers);
webView.getEngine().load("http://mysite.com");
See also:
Adding HTML Content to JavaFX Applications – 2014-1
WebKit
Calling JavaScript in the WebEngine
We can invoke JavaScript in the context of the browser by using the WebEngine's
executeScript() method.
Calling Java from the browser
On occasion, we may wish JavaScript within the browser to call back into our JavaFX application.
We do this with the JSObject class (Note this is JavaScript Object and not JSON). For example,
we may wish to get the JavaScript object that represents the browser's "window" object within the
browser. To do this we can use:
JSObject win = (JSObject) webEngine.executeScript("window");
Now that we have this JSObject instance we can use its own "setMember()" method to define
the Java class we wish to pass:
win.setMember("xyz", this);
This now allows us to call Java from the browser with:
<script>
xyz.myFunction("Hello!");
</script>
If JavaScript passes a JavaScript object to the Java class, it manifests as an instance of JSObject.
JavaFX Menus
See also:
JavaFX Menus
Page 279
Seitenansicht 278
1 2 ... 274 275 276 277 278 279 280 281 282 283 284 ... 297 298

Kommentare zu diesen Handbüchern

Keine Kommentare