JDK-8170515 : WebView. "onclick" attribute in HTML not working on Windows with Java 8u111.
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u111
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-11-25
  • Updated: 2016-11-30
  • Resolved: 2016-11-30
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Client VM (build 25.111-b14, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
WebView. "onclick" attribute in HTML not working on Windows with Java 8u111.

REGRESSION.  Last worked in version 8u101

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run attached code.
Click on "Click me" button.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Message dialog is shown.
ACTUAL -
Nothing happens.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;

import javax.swing.JOptionPane;

public class WebViewTest extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Stage stage = new Stage();
        stage.setTitle("WebViewTest");
        WebView webView = new WebView();
        stage.setScene(new Scene(webView, 400, 300));
        WebEngine webEngine = webView.getEngine();
        stage.show();
        webEngine.loadContent("<!DOCTYPE html>\n" +
                "<html>" +
                "<body>" +
                "<p><a href=\"#\" onclick=\"java.alert('Click handled')\">Click me</a><p>" +
                "</body>" +
                "</html>");
        JSObject window = (JSObject) webEngine.executeScript("window");
        window.setMember("java", new Java());
    }

    public class Java {

        public void alert(String string) {
            JOptionPane.showMessageDialog(null, string);
        }
    }
}

---------- END SOURCE ----------


Comments
This issue is due to the change in expected behaviour fixed as part of JDK-8089681 (JavaScript to Java Bindings uses weak references). Also the documentation updated as part of JDK-8154127 and JDK-8169204. If the test application has to work , you need to pass like below: Java obj = new Java(); window.setMember("java", obj); Hence closing this issue as duplicate of JDK-8089681.
30-11-2016