拦截html按钮点击 [英] Intercept html button click

查看:45
本文介绍了拦截html按钮点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击 html 按钮时是否有可能拦截?我有一个 webviewclient 加载一个带有两个按钮的登录页面.允许和拒绝.我希望您在按下拒绝按钮时进行拦截.(拒绝和允许有相同的 basUrl 和一个 js 做正确的重定向).

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).

提前致谢

推荐答案

您可能没有收到对 shouldOverrideUrlLoading() 的回调,因为只有在用户触发导航时才会调用该回调 - 如果您使用 jquery/javascript 或其他类型重定向,那么它不会被调用.

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.

如果您控制着网页,您可以添加一个 JavaScriptInterface 来回调您的 Android 应用程序并根据您的喜好在此处处理它:http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

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

使用 JSI,您只需在应用中注册一个函数,然后在页面的 javascript 中调用它.

With JSI you simply register a function in your app and then call it in the page's javascript.

如果您无法控制网站,如果您熟悉网页的结构/DOM,您仍然可以自己注入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.

这篇关于拦截html按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆