UIWebViewNavigationTypeOther Vs UIWebViewNavigationTypeLinkClicked - iphone

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//my code
}
Currently my above delegate method is called, once i touch inside in my webview.
So i want to know what is the difference between following 2 navigationtype: UIWebViewNavigationTypeOther & UIWebViewNavigationTypeLinkClicked.
Because some of the URL on selection provides navigation Type as UIWebViewNavigationTypeOther & some provide UIWebViewNavigationTypeLinkClicked.
From the apple document i cannot able to clear my self.

UIWebViewNavigationTypeLinkClicked happens if the user taps a <a href=""> style link, if the change is done from within Javascript (onclick event for example) UIWebViewNavigationTypeOther is used.
Furthermore UIWebViewNavigationTypeOther is used if you first load a page or you'll be redirected by a meta refresh or something

Related

Hyperlink click method in UIWebview

I have one UIWebView in my iphone app and I have to detect on click method whenever user will click on any hyperlink.
I want to call one method when user will click on hyper link I know about the method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
but it will be detected whenever any link will be loaded whether user has clicked or not on hyperlink but I want to call method only when user will click on any method.
Please get me out of this issue.
-Thanks in advance.
You can check the UIWebViewNavigationType.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog("User tapped a link.");
}
}
See UIWebView Class Reference for more information.

Calling Objective-C method by clicking text inside UIWebView

I query a SQLite db and the query returns some links: I can display them in a UITextView or in a UIWebView.
What I need to know is: is there a way to bind an action to a link inside a UIWebView (or even UITextView)? I don't want to open a webpage, I just want to execute a method of Objective-C as the link was a button. Is this possible?
Yes, this is possible via JavaScript, see this doc: Calling Objective-C Methods From JavaScript.
Use the delegate method
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)aRequest navigationType:(UIWebViewNavigationType)navigationType
and check for UIWebViewNavigationTypeLinkClicked, then inspect the [aRequest URL] to determine what the link action should be.

iphone notification from javascript to objective C

I've designed my main view using HTML, CSS and some images. It looks very nice. I'm using some images that are clickable in HTML code.
On click of some image, I want to load some view accordingly.
Is it possible? If yes, please suggest me how to do it.
If tutorial or some sample code is available please share it.
Implement the following UIWebView Delegate Method and call your Objective methods
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog(#"LINK CLICKED......");
//return NO;
}
return YES;
}
You can look into PhoneGap for some sample code.
There are two parts. First you define a custom scheme for you application that is only used to communicate between the web page and the delegate. Could just be 'foo:' as it will be private to the page and host. You then handle this custom scheme in the delegate shouldStartLoadWithRequest method and return NO.
With a clickable link, you can just set the href to something that starts with your custom scheme. If you need to send messages at arbitrary times, you can use javascript to set the window.location to a url with your custom scheme.

Prevent app exit from UIWebView link

I have a UIWebView in my app which shows the clients webpage, however I would like to retain the user within the app if they choose to browse the webpage.
Can I prevent it breaking out to Safari when a link is clicked?
Try implementing UIWebViewDelegate's:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
HTH.

Have iPhone webpage URL open in specific view in application

I have an application that acts like an internet browser for one webpage. If the webpage is in one view, can I have it act so when a specific URL is selected that it will open the URL in a different view?
Yes. In your webViewController, implement this
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
Check to see if it's the url you're interested in, then create and push a view that displays the web page.
Oh, and return NO to prevent the load from occurring in this view.