views:

532

answers:

2

Hi,

I am using a custom webview to show a tabbar when user touches on the webview. But when I clicked on a link in a webview, tabbar is shown for a little time and then page loads. I am using this custom webview to detect touch: http://github.com/psychs/iphone-samples/blob/b772b963f2acf18d478b41b44555992fcd8d4f31/WebViewTappingHack/Classes/PSWebView.m

Can I detect if a link clicked or not? Because a link stands on the webview, webview detects the touch and also it loads the page... I want to prevent it.

Thanks in advance.

+2  A: 

Using Javascript

Instead of preventing the loading of the page, I would inject Javascript into the webview so that touching the link doesn't do anything.

I've answered a question similar to this not too long ago. Instead of disabling all links (like the other question) just look for the specific link you'd like to disable and remove its href attribute.

Using a UIWebview Delegate

Alternatively, if you want to be able to respond to a user attempting to click the link (perhaps to give them a message), you can set the UIWebview's delegate and implement the webView:shouldStartLoadWithRequest:navigationType: method and return NO if the URL attempting to be loaded is the one you'd like to block.

As an aside, it's usually best practice to maintain a whitelist as opposed to a blacklist for this sort of exclusion. Rather than blocking links you don't want it might be better to block all links, except for the ones you know are safe to navigate to.

Ben S
Actually I want to prevent to show tabbar, not loading page... When user touches on the webview and if it is link which touched on, then I do not want to show the tabbar, but if it is NOT link I want to show tabbar... Hope it is more clear now.
Uygar Y
A: 

OK, I do a workaround and solved by myself...

My links are at the top & bottom of the page so I got screen coordinates by the following code and if pos.y < some value and pos.y > some value then do not show the menu...

UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y);

Hope this helps someone...

Uygar Y