Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8101291

make more available the url loaded by the webview

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Not an Issue
    • P4
    • None
    • fx2.0.2
    • javafx
    • web

    Description

      I want to get the url of the web page displayed by the webview.

      When the user clicks on a web link, I can catch the MouseEvent and get the url into the handler.

      But the user can go back, directly, through right-clicking into the WebView. And then, it's harder to get the url.

      Well, I have discovered I can add a listener to the 'state' property.

      webEngine.getLoadWorker().stateProperty().addListener(
      new ChangeListener<State>() {
      @Override
      public void changed(ObservableValue<? extends State> ov,
      State oldState, State newState)
      {
      System.out.println("stateProperty.ChangeListener: newState=" + newState + " message=" + webEngine.getLoadWorker().getMessage());
      }
      });
       
      Then, when the user goes back, the outputs are:

      stateProperty.ChangeListener: newState=SUCCEEDED message=Loading http://news.google.fr/nwshp?hl=fr&tab=ln
      stateProperty.ChangeListener: newState=SCHEDULED message=Loading http://news.google.fr/nwshp?hl=fr&tab=ln
      stateProperty.ChangeListener: newState=RUNNING message=Loading http://news.google.fr/nwshp?hl=fr&tab=ln
      stateProperty.ChangeListener: newState=SUCCEEDED message=Loading http://maps.google.fr/maps?hl=fr&tab=wl
      stateProperty.ChangeListener: newState=SCHEDULED message=Loading http://maps.google.fr/maps?hl=fr&tab=wl
      stateProperty.ChangeListener: newState=RUNNING message=Loading http://maps.google.fr/maps?hl=fr&tab=wl
      stateProperty.ChangeListener: newState=SUCCEEDED message=Loading http://www.google.fr/advanced_search?hl=fr
      stateProperty.ChangeListener: newState=SCHEDULED message=Loading http://www.google.fr/advanced_search?hl=fr
      stateProperty.ChangeListener: newState=RUNNING message=Loading http://www.google.fr/advanced_search?hl=fr
      stateProperty.ChangeListener: newState=SUCCEEDED message=Loading http://www.google.fr/
      stateProperty.ChangeListener: newState=SCHEDULED message=Loading http://www.google.fr/
      stateProperty.ChangeListener: newState=RUNNING message=Loading http://www.google.fr/
      stateProperty.ChangeListener: newState=SUCCEEDED message=Loading http://www.google.fr/advanced_search?hl=fr
      stateProperty.ChangeListener: newState=SCHEDULED message=Loading http://www.google.fr/advanced_search?hl=fr
      stateProperty.ChangeListener: newState=RUNNING message=Loading http://www.google.fr/advanced_search?hl=fr
      stateProperty.ChangeListener: newState=SUCCEEDED message=Loading http://www.google.fr/

      So, I can get the url through the 'message' property.

      But I need to parse the 'message' property's value.

      Is it possible to split the 'message' property ?
      into 2 properties, one containing the 'Loading' part (or whatever is the first part of the message's value), and another one containing only the url.

      Attachments

        Activity

          People

            peterz Peter Zhelezniakov
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: