Have iPhone webpage URL open in specific view in application - iphone

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.

Related

how to perform an action in iphone application on click in webview

I need to implement a functionality such that I have there is a login screen which sends an http request packet, gets a json response(a boolean and a routing link) and opens a webview. I have done this successfully. But further what I need to do is that when I click sign out in the webview, I should get back to the native login screen.How can I achieve that?
Check this call back method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
}
You get this call back when you click link in webview.

UIWebViewNavigationTypeOther Vs UIWebViewNavigationTypeLinkClicked

- (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

Alertview in webapp - This link opens in a new window http://wwww

I am currently developing a little webapp with iWebKit I joined a UIWebView.
And I have a little problem, I would like the external links before opening in Safari displays a alertview "This link opens in a new window".
AlertView With:
Title: External Links (No URL)
Message: Would you open this link external mobile safari ?
Button: OK Cancel
How to do that just please?
Thank you very much for your help;)
In the object that is designated as the UIWebViewDelegate add the following:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return [self verifyUserWantsToNavigateAwayFromApp];
}
The method that you'll have to write verifyUserWantsToNavigateAwayFromApp. Is where you should pop up the alerts and wait for the UIAlertViewDelegate to get the user's answer. Return YES to navigate, NO to cancel.

UIWebView: open some links in Safari, some within the view

My app features content that (for text formatting reasons) is presented in an UIWebView. Within the content there are links, some of which should open their target in mobile Safari, while others should navigate within the content.
So far, I've catched the link requests using a UIWebView delegate. In my implementation of
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
I'd check the requests URL using lastPathComponent or pathComponents for known elements to determine whether to open the link externally or within the view.
However, I just found out said methods are only available since iOS 4.0, which would render the app useless on iPad. Plus I have the feeling I'm using a dirty solution here.
Is there another way to somehow "mark" the links within my content in a way that makes them easy to distinguish later, when processing the request in the delegate method?
Thanks alot!!
You could covert the URL request into a string, and do a compare for a subdirectory on your website, such as in URLs that only start with "http://www.sample.com/myapp/myappswebcontent/", against the initial substring of your URL. Anything else, send to Safari.
You should set a policy delegate of web view:
For instance in the controller, that contains a web view
[webView setPolicyDelegate:self];
and then override a decidePolicyForNavigation method (this is just an example):
- (void)webView:(WebView *)sender decidePolicyForNavigationAction: (NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id <WebPolicyDecisionListener>)listener
{
if ([[actionInformation objectForKey:WebActionNavigationTypeKey] intValue] == WebNavigationTypeLinkClicked) {
[listener ignore];
[[NSWorkspace sharedWorkspace] openURL:[request URL]];
}
else
[listener use];
}
you can distinguish there kind of link and ignore or use the listener. If you ignore it, you can open the link in safari, if you use it, the link will open in your webview.
HTH

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.