ios webview how to monitor the webview load a new url - iphone

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

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.

Stopping video to play in UIWebView

I am loading a page in UIWebView. The page contain thumbnails to play. When I click any of the thumbnails, it launches in any default player. I want it should not play in default player, I want to play the video in MPMovieController With Custom controls whenever I click on the thumbnail in UIWebview. Could I stop the videos to play in default player??
This would require to get the movie url and play it in MPMoviePlayer and stop the redirection of webview.
LOGIC:
in webview's delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
get the URL from NSURLRequest's NSURL and then get the redirection url with NSURL absoluteString
compare the extension of the file in url. if it is of video e.g. .mov/.mp4,
load your MPMoviePlayer with the URL to play it in your application and return NO; for this delegate method.
If you have access to thumbnail code you can put javascript method which will do simple redirect:
<a href="#" onClick="javascript:play_native_video_url(url); >thumbnail here</a>
play_native_video_url(url) {
window.location = "play://"+url;
}
UIWebView delegate will catch this redirect with custom scheme (not http:):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// Define if it is your custom scheme:
if ([request.URL.host isEqualToString:#"play"]) {
// get url and play it with native MPMoviePlayer...
return NO; // do not let WebView process it
}
}
written from memory

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

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.