Get notified about a page change in UIWebView(获取有关 UIWebView 中的页面更改的通知)
问题描述
我很好奇是否有一种方法可以检测 UIWebView
内显示网站的变化.在我正在开发的应用程序中,我们使用 UIWebView
来呈现部分功能,这些功能基本上是用户需要遵循的几个步骤.但是,在这些步骤结束时,我需要识别一个特定页面,然后应用程序需要显示不同的视图.
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
to present a part of the functionality which are basically a few steps the user needs to follow. However, the will be a specific page at the end of these steps that I need to identify and after which the app needs to display a different view.
不幸的是,UIWebViewDelegate
似乎没有解决问题.
Unfortunately the UIWebViewDelegate
doesn't seem to do the trick.
推荐答案
如果用户步骤在不同的页面上是分开的,而UIWebView
需要加载不同的步骤,这确实应该可以委托方法.
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.
在这个例子中,我们说用户经历了 3 个步骤,分别命名为 step1.htm、step2.htm,最后是 step3.htm.此代码将检测用户何时到达第三步也是最后一步.
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;
}
请注意,使用 absoluteString
方法可能不是找出用户浏览位置的最佳方法.看看query
、path
、parameterString
等...
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...
这篇关于获取有关 UIWebView 中的页面更改的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取有关 UIWebView 中的页面更改的通知


基础教程推荐
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 固定小数的Android Money Input 2022-01-01