Disable hyperlinks in UIWebView
I want to disable hyperlinks in UIWebVIew after the initial page loaded without disabling the 开发者_JAVA百科scrolling feature. That is, I should have user interaction enabled.
You can work with webView shouldStartLoadWithRequest like this:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *loadURL = [[request URL]retain];
//change next line to whatever condition you need, e.g.
//[[loadURL relativeString] ....] contains a certain substring
//or starts with certain letter or ...
if([[loadURL scheme] isEqualToString: @"file"])
{
[loadURL release];
return TRUE;
}
[loadURL release];
return FALSE;
}
You also have to set the webViews delegate an object of class where this method is implemented in: [webView setDelegate:my...];
By the implementation above, no url is loaded except those for which the condition is true. At least for the url of the first site it has to be true. The code above works for a web view initially loaded with contents of a file, containing only links to 'http://' or 'https://' or ...
精彩评论