I am trying to block URLs with a certain keyword in a JavaFX webview. So far, I have tried using webEngine.locationProperty().addListener()
to listen for a change in state. While this is successful in blocking the URL, it unfortunately leaves the locationProperty set to the value that I am trying to block. This causes problems for links that use references on the page.
Two solutions I have tried for setting locationProperty back to its correct value:
- Calling
webEngine.load()
. This causes the page to refresh and the user loses work. - Calling
webEngine.getHistory().go(0)
. As it says in the documentation, this does nothing.
I can think of two general ways to solve this problem:
- Find a place earlier in the chain of properties than locationProperty that gets changed to listen.
- Figure out a way to change locationProperty back to its correct value without reloading the page. (I think this might be possible through reflection which I've been trying to avoid up to this point.)
Do either of these solutions sound reasonable and if so what is the best way to implement them?