programmatic click in Android WebView

前端 未结 2 1809
遥遥无期
遥遥无期 2020-12-01 11:27

I have a website with href in it which redirected me to https



        
2条回答
  •  不思量自难忘°
    2020-12-01 11:49

    You'll have to add a javaScript interface to the WebView to call a JavaScript function from android code.

    Try something like this:-

        Button buttoner = (Button) findViewById(R.id.button1);
        buttoner.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
                JavascriptInterface javasriptInterface = new JavascriptInterface(RostelecomLoginActivity.this);
                webView.addJavascriptInterface(javasriptInterface, "MyInterface");
                webView.loadUrl("javascript:(function(){document.getElementById('mA').click();})()");
            }
        });
    

提交回复
热议问题