Knowing when AJAX has loaded in UIWebView(知道何时在 UIWebView 中加载了 AJAX)
问题描述
我有一个 UIWebView
并且一个页面有一个 AJAX 组件,当用户单击按钮时,它的内容会发生变化.我如何知道内容何时加载到 UIWebView
中?
I have a UIWebView
and one page has an AJAX component whose content changes when the user clicks a button. How can I know when the content has loaded inside the UIWebView
?
推荐答案
你需要做两件事:
在您的 JavaScript 代码中,使用
XMLHTTPRequest
信号表明 AJAX 请求已通过自定义 URL 完成:
In your JavaScript code, have the
XMLHTTPRequest
signal that the AJAX request is complete with a custom URL:
var req = new XMLHttpRequest();
req.open('GET', 'http://www.mozilla.org/', true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200) {
window.location = "myspecialurl:foo"
}
}
};
在您的本机代码中,您需要实现一个 UIWebView
委托来侦听此自定义 URL:
In your native code, you'll need to implement a UIWebView
delegate that listens for this custom URL:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if([[[request URL] absoluteString] isEqualToString:@"myspecialurl:foo"]) {
// Your code for when the AJAX request completes.
return NO;
}
return YES;
}
不保证此代码可以解析/编译,但应该让您知道如何去做.
No assurances this code parses/compiles but should give you the idea how to do it.
这篇关于知道何时在 UIWebView 中加载了 AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:知道何时在 UIWebView 中加载了 AJAX


基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01