我已成功将UIWebView
添加到UIAlertView
并在警告弹出窗口中显示Html页面。
但现在我想跟踪UIWebView
中存在的元素。那么请您告诉我如何才能知道在UIButton
弹出窗口中显示的UIWebView
中点击了哪个alert
?
代码:
NSString *html =@"<!DOCTYPE html><html><body><form action=\"action_page.php\">First name:<br><input type=\"text\" name=\"firstname\"><br> Last name:<br> <input type=\"text\" name=\"lastname\"><br><br> <input type=\"submit\"> </form> <p>Note that the form itself is not visible.</p> <p>Also note that the default width of a text field is 20 characters.</p> </body> </html>";
UIWebView *webView = [[UIWebView alloc] init];
[webView setFrame:CGRectMake(0,0,200,400)];
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
[webView loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"www.google.com"]];
webView.delegate = self;
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
[av setValue:webView forKey:@"accessoryView"];
[av show];
答案 0 :(得分:0)
添加该Web视图时,需要将委托设置为存在警报的当前视图控制器。因此,在web view delegate
方法中,您可以使用javascript query
跟踪点击事件。
你可以在web view
方法中获取它:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//javascrip evalution code
}