這可能是一個瘋狂的問題,但我期待在iOS應用程序中使用UIButton,當您點擊它時,它將依次單擊加載在隱藏的UIWebView中的網頁上的超鏈接。可以使用UIButton在UIWebView中執行超鏈接單擊嗎?
鏈接也可以通過JavaScript調用觸發我只是不確定是否可以從UIButton到UIWebView?
感謝阿龍
這可能是一個瘋狂的問題,但我期待在iOS應用程序中使用UIButton,當您點擊它時,它將依次單擊加載在隱藏的UIWebView中的網頁上的超鏈接。可以使用UIButton在UIWebView中執行超鏈接單擊嗎?
鏈接也可以通過JavaScript調用觸發我只是不確定是否可以從UIButton到UIWebView?
感謝阿龍
你可以打電話給你的UIWebView中的javascript從您的UIButton單擊處理程序,直接調用你的JavaScript函數,句柄href點擊。
請參閱Adding html to a ui web view at runtime in code, based on a switch
我只是使用HTML表單與一個提交按鈕,而不是建議。我已經做到了這一點,它更簡單。喜歡的東西:
- (NSString *)makeSubmitForm
{
NSMutableString *ms = [NSMutableString string];
[ms appendString:@"<p><form action=\"formentry\">"];
[ms appendString:@"<input style=\"submit\" type=\"submit\" value=\"Submit\" />"];
[ms appendString:@"<input type=\"hidden\" name=\"fieldtype\" value=\"submit\" />"];
[ms appendString:@"</form>"];
return ms;
}
,然後就尋找它在你的UIWebViewDelegate。下面的代碼做這一點,並檢查是否存在(如文本字段輸入)等形式進入的東西
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *surl = [[request URL] absoluteString];
NSRange ner = [surl rangeOfString:@"formentry?"];
if (ner.location != NSNotFound){
NSString *argstr = [surl substringFromIndex:ner.location+ner.length];
NSMutableDictionary *md = [NSMutableDictionary dictionary];
NSArray *args = [argstr componentsSeparatedByString:@"&"];
for (int i=0; i < args.count; i++){
NSString *keyval = [args objectAtIndex:i];
NSArray *pair = [keyval componentsSeparatedByString:@"="];
[md setObject:[pair objectAtIndex:1] forKey:[pair objectAtIndex:0]];
}
[MyDelegate tellItWhatever:md];
}
return NO;
}