Hi friends,
Again I'm here to share something new with you.. If you want to do some operations on URL click in UIWebview of iPhone/iPod/iPad then you need to use the below delegate method of UIWebview. You have to set WebViewDelegate in header file of your class.
#pragma mark-------------------------
#pragma mark WebView Delegate Method
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.relativeString;
NSLog(@"%@",urlString);
NSLog(@"%@",[request.URL lastPathComponent]);
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
if([[urlString substringToIndex:5] isEqualToString:@"https"] || [[urlString substringToIndex:5] isEqualToString:@"http:"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
}
else
{
// do your operation within Application
}
return NO;
}
return YES;
}
Hope you like this..
Thanks ,
Nilesh Prajapati
Again I'm here to share something new with you.. If you want to do some operations on URL click in UIWebview of iPhone/iPod/iPad then you need to use the below delegate method of UIWebview. You have to set WebViewDelegate in header file of your class.
#pragma mark-------------------------
#pragma mark WebView Delegate Method
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.relativeString;
NSLog(@"%@",urlString);
NSLog(@"%@",[request.URL lastPathComponent]);
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
if([[urlString substringToIndex:5] isEqualToString:@"https"] || [[urlString substringToIndex:5] isEqualToString:@"http:"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
}
else
{
// do your operation within Application
}
return NO;
}
return YES;
}
Hope you like this..
Thanks ,
Nilesh Prajapati
No comments:
Post a Comment