2
I can’t tell when an Iframe is changed
I use a listener
to know whenever the page is loaded into the Webengine, however this listener
cannot know when Iframe is changed/ loaded.
Is there any way to detect the differences/ changes within the Iframe
Code: HTML
<iframe id="principal" name="principal"</iframe>
JavaFx
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
System.out.println("Location" + engine.getLocation());
Document doc = engine.getDocument();
HTMLIFrameElement iframeElement = (HTMLIFrameElement) doc.getElementById("principal");
Document iframeContentDoc = iframeElement.getContentDocument();
//Element rootElement = iframeContentDoc.getDocumentElement();
//System.out.println(rootElement.getTextContent());
NodeList nodeList = iframeContentDoc.getElementsByTagName("a");
System.out.println("Total de tabs " + nodeList.getLength()); // <--- Dá 0 porque o Iframe ainda não estava carregado, se esperar um pouco consigo obter a informação, contudo nunca sei quando este Iframe está completamente carregado ou foi alterado
}
}
});
It is possible to put a listener
on this component? How can I know when you have loaded or changed the content?
Looks like you want to do
addListener
in aNodeList
or even in aDocument
, but I haven’t seen these options on these interfaces. You can see the full content of the Webengine, with thedocumentProperty()
his. Take a look at the documentation of the Webengine class, it seems possible to connect to the Javascript of the page, so that Javascript calls Java code, if possible, maybe you can put a Javascript Listener in your HTML frame. If you succeed, answer here, it would be a very good answer :D– Douglas