将警报从UIWebView传递到iOS应用程序
pass alert from UIWebView to iOS app
我已经创建了一个应用程序,它运行良好。我唯一需要的就是将警报从uiwebview传递到我的iOS应用程序。
我的uiwebview 上有这个警报
<div id="alerts" class="alerts">
<p class="alert-red">ok. come back again tomorrow, not now.</p>
我想将此警报转移到我的应用程序中,并使其成为uialertview
UIAlertView *errr = [[UIAlertView alloc]initWithTitle:@"nil" message:@"ok. come back again tomorrow, not now." delegate:self cancelButtonTitle:@"Ok, Got it" otherButtonTitles:nil, nil];
[errr show];
知道如何达到这个结果吗?当此警报显示在uiwebview上时,我是否需要NSNotification来侦听?
我试过这种
NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"var targetDiv = document.getElementById('alerts').getElementsByClassName('alert-red')[0];"];
NSLog(@"%@",theTitle);
因此,我可以尝试从"红色警报"中检索该消息,但不起作用。
我是javascript和html 的新手
这是用于解决此问题的典型解决方法:
当你想显示此警报时,请在你的网页中运行以下javascript代码:
window.location = 'custom_action';
然后在objc中在控制器上实现shouldStartLoadWithRequest
(并设置yourWebView.delegate = yourController
)
-(BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
// detect when the webview switches to this custom url
if([[[request URL] absoluteString] isEqualToString: @"custom_action"]) {
UIAlertView *errr = [[UIAlertView alloc]initWithTitle:@"nil" message:@"ok. come back again tomorrow, not now." delegate:self cancelButtonTitle:@"Ok, Got it" otherButtonTitles:nil, nil];
[errr show];
// this prevents the webview from actually trying to load the custom url
return NO;
}
// allow the url to load if its not your custom url
return YES;
}
相关文章:
- 如何在iOS应用程序中从Firebase中删除超过6小时的数据
- 使用指针为ios应用程序&Javascript网站
- window.open()在使用phone gap的iOS应用程序上不起作用
- 在iOS应用程序的分析云代码上运行crypto-js的问题
- Phonegap:灵活的iOS应用程序更新(无应用商店)
- Meteor测试/部署iOS应用程序以连接真实服务器(而非本地主机)
- Phonegap IOS应用程序图像缩放多点触控
- 在iOS应用程序中动态加载“代码逻辑”是否可行
- iOS应用程序在Apple-TV上播放youtube视频
- phonegap:如何从ios应用程序上传docx,pdf文件
- 调用嵌入在iOS应用程序中的Javascript
- iOS应用程序,链接到在浏览器中打开的网站,链接在网站关闭浏览器
- iOS 应用程序(iPhone 和 iPad)中的阿拉伯字体
- 使用 HTML5 打开我的 iOS 应用程序并向其传递参数
- 如何在ios应用程序中更改位置iPhone时制作旋转照片
- 无法将插件添加到 Cordova 3.0 的 ios 应用程序
- 将脸书评论添加到我的iOS应用程序
- 从本机iOS应用程序调用带有变量的Javascript函数
- 是否可以通过iOS应用程序访问rails数据库
- 在ios应用程序中使用谷歌地图javascript api