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

WebView deletes text when document.execCommand is called from Java code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u15
    • javafx
    • Mac OS X 10.7.5, Java 1.7.0_15

    • web

      If I call document.execCommand("bold") on a WebView from Java code, with some text selected, the text becomes bold, but as soon as the text is deselected the text is deleted. This does not happen if document.execCommand("bold") is called from a javascript generated event.

      ---

      WebViewTest.java:

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      public class WebViewTest extends Application {
          public static void main(String[] args) {
              launch(args);
          }

          @Override
          public void start(Stage primaryStage) {
              primaryStage.setTitle("Hello World!");
              final WebView webView = new WebView();
              webView.getEngine().load(getClass().getResource("test.html").toExternalForm());

              StackPane root = new StackPane();
              VBox box = new VBox();
              Button button = new Button();
              button.setText("Bold");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      webView.getEngine().executeScript("bold();");
                  }
              });
              box.getChildren().add(button);
              box.getChildren().add(webView);
              root.getChildren().add(box);
              primaryStage.setScene(new Scene(root, 300, 250));
              primaryStage.show();
          }
      }

      ---

      test.html:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
      <head>
          <title>TinyMCE Test</title>
          <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
          <script>
              window.onload = function() {
                  document.designMode = "on";
              };

              function bold() {
                  document.execCommand("bold");
              }
          </script>
      </head>
      <body>
          <br /><br /><input type="button" value="Bold" onclick="bold();" />
      </body>
      </html>

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: