问题
is there any possibility to intercept when a user clicks on a html button? I ve an webviewclient that load a login page with two buttons. Allow and Deny. I would you like to intercept when the deny button is pressed. (Deny and allow have the same basUrl and a js do the correct redirect).
thanks in advance
回答1:
You are probably not getting a callback to shouldOverrideUrlLoading() because that is only called if the user triggers the navigation - if you use jquery/javascript or some other kind of redirect, then it will not be called.
If you are in control of the web page, you can add can a JavaScriptInterface to call back to your Android app an handle it however you like here: http://developer.android.com/guide/webapps/webview.html#BindingJavaScript
With JSI you simply register a function in your app and then call it in the page's javascript.
If you are not in control of the website, you can still inject the javascript yourself if you are familiar with the structure/DOM of the web page.
回答2:
Sounds like a case for implementing WebViewClient.shouldOverrideUrlLoading(), surely?
来源:https://stackoverflow.com/questions/4396450/intercept-html-button-click