What I want to do is to replace part (s) of the content of the HTML page of the web page (which is currently loaded inside the WebView engine) with my own HTML content.
As a simple example, I want to replace every background color of the loaded page with RED. The value I will need to add or replace is the existing bgcolor attribute of the body with my own value. What should I do to achieve this?
Here is the basic browser code based on the JavaFX WebView component:
public class BrowserTest extends Application { public static void main ( String[] args ) { launch ( args ); } public void start ( Stage stage ) { stage.setTitle ( "WebView" ); Browser browser = new Browser (); browser.load ( "http://google.com" ); Scene scene = new Scene ( browser ); stage.setScene ( scene ); stage.show (); } public class Browser extends Region { final WebView browser; final WebEngine webEngine; public Browser () { super (); browser = new WebView (); webEngine = browser.getEngine (); getChildren ().add ( browser ); } public void load ( String url ) { webEngine.load ( url ); } private Node createSpacer () { Region spacer = new Region (); HBox.setHgrow ( spacer, Priority.ALWAYS ); return spacer; } protected void layoutChildren () { double w = getWidth (); double h = getHeight (); layoutInArea ( browser, 0, 0, w, h, 0, HPos.CENTER, VPos.CENTER ); } protected double computePrefWidth ( double height ) { return 750; } protected double computePrefHeight ( double width ) { return 500; } } }
Some Oracle docs had a good example of this method, but since the last update of JavaFX and the site, I have not been able to find it at all. Maybe someone has a link to old documents ...
Note: Jewelsea also suggested a good way to make post-changes (when the page is loaded), but I need a precisely βload-whileβ solution for mine so that WebView does not double-render twice (before and after the changes).
Mikle garin
source share