How UIWebView detect lt;img src=quot;...quot; /gt; is tapped(UIWebView 如何检测 lt;img src=quot;...quot;/gt;被窃听)
问题描述
我知道下面的方法可以检测链接元素点击.但是我想知道 UIView
是否可以检测到 img
元素是否被点击?
I know that method below can detect a link element tap. But I want to know if the UIView
can detect if the img
element is tapped?
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
switch (navigationType) {
case UIWebViewNavigationTypeLinkClicked:
NSLog(@"link is click");
//do something
break;
default:
break;
}
return true;
}
一些html源代码如下:
Some html source like below:
<p>xxxxxxxxx</p>
<p><img src="http://imgs.ebrun.com/resources/2015_06/2015_06_16/201506167911434413787546.jpg"> </p>
<p>xxxxxxxxx。</p>
<p><img src="http://imgs.ebrun.com/resources/2015_06/2015_06_16/201506167911434413787546.jpg"> </p>
<p>xxxxxxxxx。</p>
你能告诉我如何使用示例代码来做到这一点吗?谢谢.
Could you show me how to do it using sample code? Thanks.
推荐答案
你的img标签没有html点击事件.如果你可以像下面这样制作你的图像 -
Your img tag does not have html click event. If you can make your image like below way -
<p>xxxxxxxxx</p>
<p><img src="http://imgs.ebrun.com/resources/2015_06/2015_06_16/201506167911434413787546.jpg" onclick="myfunction()"> </p>
<p>xxxxxxxxx。</p>
<p><img src="http://imgs.ebrun.com/resources/2015_06/2015_06_16/201506167911434413787546.jpg" onclick="myfunction()"> </p>
<p>xxxxxxxxx。</p>
然后您可以在 UIWebView 委托方法中捕获您的 img 点击事件 - shouldStartLoadWithRequest.
Then you can catch your img click event within UIWebView Delegate method - shouldStartLoadWithRequest.
其他可能的选项 -
否则,您已经编写了一个 javascript 方法,该方法将 OnClick 方法动态添加到所有 IMG 标记.并在您的页面加载到 UIWebView 时调用此 javascript 方法 -
Otherwise you have write a javascript method which dynamically add OnClick method to all IMG tags. And call this javascript method when your page load in UIWebView -
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
//Execute javascript method or pure javascript if needed
[_webView stringByEvaluatingJavaScriptFromString:@"methodName();"];
}
这篇关于UIWebView 如何检测 <img src="..."/>被窃听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIWebView 如何检测 <img src="..."/>被窃听


基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01