webView攔截H5按鈕事件

需要遵守協議UIWebViewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

NSString *requestString = [[[request URL] absoluteString]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"requestString : %@",requestString);

NSArray *components = [requestString componentsSeparatedByString:@"|"];
NSLog(@"=components=====%@",components);

NSString *str1 = [components objectAtIndex:0];
NSLog(@"str1:::%@",str1);

NSArray *array2 = [str1 componentsSeparatedByString:@"/"];
NSLog(@"array2:====%@",array2);

NSInteger coun = array2.count;
NSString *method =[NSString stringWithFormat:@"%@/%@",array2[coun-2],array2[coun-1]];
NSLog(@"method:%@",method);

//採購申請提交成功//採購申請刪除//採購申請戰敗
if ([method isEqualToString:@"purchase/applys"])//查看詳情,其中紅色部分是HTML5跟咱們約定好的,相應H5上的按鈕的點擊事件後,H5發送超鏈接,客戶端一旦收到這個超鏈接信號。把其中的點擊按鈕的約定的信號標示符截取出來跟本地的標示符來進行匹配,如果匹配成功,那麼就執行相應的操作,詳情見如下所示。
{
    NSLog(@"InviteBtn01");
    [self dismissPurchaseSelf];
   // [webView.superview.window popViewControllerAnimated:YES];
    //[self.navigationController popViewControllerAnimated:YES];
    return NO;
}
return YES;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章