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.
Related
**Situation is like this,my webview load a base request url,when user clicked the html or anyother action,the webview will laod a new url. Can I get the webview changed events? If window.location.href can be worked well,and how?
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
this method will be performed every time you click the button of html
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.
- (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
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.
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.