将 UIWebView 添加到 UIAlertView iOS



我已成功将UIWebView添加到UIAlertView并在警报弹出窗口中显示 Html 页面。但是现在我想跟踪UIWebView中存在的元素。那么,您能否告诉我如何知道在弹出窗口中单击UIWebView显示alert哪个UIButton

法典:

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];

添加该 Web 视图时,需要将委托设置为存在警报的当前视图控制器。因此,在web view delegate方法中,您将能够使用 javascript query .

您可以通过web view方法获取它:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
        //javascrip evalution code
}

最新更新