I\'m curious if there\'s a way to detect a change of the displayed website inside a UIWebView
. In an app I\'m working on we\'re using a UIWebView
t
If the user steps are separated on different pages, and the UIWebView
needs to load the different steps, this should indeed be possible with the delegate methods.
In this example, we say that the user goes through 3 steps, named step1.htm, step2.htm and finally step3.htm. This code will detect when the user reaches the third and final step.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString isEqualToString:@"http://www.example.com/step3.htm"]) {
// The user reached step 3!
}
return YES;
}
Note that using the absoluteString
method might not be the best way to find out where the user is browsing. Take a look at query
, path
, parameterString
, etc...
in Swift 4
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if request.url?.absoluteString == "http://www.example.com/step3.htm" {
// The user reached step 3!
}
return true
}