确定UIWebview的提交按钮单击

编程入门 行业动态 更新时间:2024-10-25 08:21:51
本文介绍了确定UIWebview的提交按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有多个按钮的UIWebView页面.需要确定点击了UIWebView.

I have a UIWebView page with multiple button . Need to identify which button is clicked of the UIWebView.

UIWebview加载内容的页面源:

Page source for UIWebview load contents:

<form action="settings_personal.php" data-ajax="false" method="post"> <input type="submit" name ="btn_settings_personal" value=" Goals (Personal data) " data-icon="star" data-theme="g" /> </form> <form action="settings_global.php" data-ajax="false" method="post"> <input type="submit" name ="btn_settings_global" value=" Settings " data-icon="gear" data-theme="g" /> </form> <form action="" data-ajax="false" method="post"> <input type="submit" name ="btn_web_access" value=" Web Plattform Access " data-icon="plus" data-theme="h" /> </form>

我需要确定为名为"btn_web_access"的按钮单击的按钮???

I need to identify button clicked for 'btn_web_access' named button ???

我实现了以下内容:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{ NSString* clicked = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('btn_web_access').click();"]; NSLog(@"CLICK %@",clicked); }

但是没有用..谢谢.

推荐答案

只需使用请求的URL属性来区分加载请求的目标:

Just use the request's URL attribute to distinguish the load request's target:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{ NSLog(@"url: %@", [[request URL] absoluteString]); return YES; }

根据所调用的URL,您知道单击了当前显示的网页中的哪个按钮(甚至任何链接).然后采取必要的操作,不要忘记返回一个BOOL值,指示是否实际加载了所请求的URL.

Based on the URL being called, you know which button (or even any link) of your currently shown webpage was clicked. Then take the action being needed and don't forget to return a BOOL value indicating wether or not to actually load the requested URL.

在Swift中,您可能拥有

In Swift you might have

func webView(webView:UIWebView, shouldStartLoadWithRequest request:NSURLRequest, navigationType:UIWebViewNavigationType) -> Bool { if (navigationType == .FormSubmitted) { print("was the 'submit' form") } let u = request.mainDocumentURL print("local or remote url was " ,u) return true // allow the form to in fact send the form }

更多推荐

确定UIWebview的提交按钮单击

本文发布于:2023-11-27 15:53:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   UIWebview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!