我可以在 UIWebViewDelegate 中处理警报吗?

编程入门 行业动态 更新时间:2024-10-10 14:26:18
本文介绍了我可以在 UIWebViewDelegate 中处理警报吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 <script language="javascript"> alert("Hell! UIWebView!"); </script>

我可以在我的 UIWebView 中看到警报消息,但我可以处理这种情况吗?

I can see the alert message inside my UIWebView but can I handle this situation?

更新:

我正在将网页加载到我的 UIWebView 中:

I'm loading a web-page into my UIWebView:

- (void)login { NSString *requestText = [[NSString alloc] initWithFormat: @"%@?user=%@&password=%@", DEFAULT_URL, user.name, user.password]; // YES, I'm using GET request to send password :) NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:requestText]]; [webView loadRequest:request]; }

目标页面包含一个JS.如果用户名或密码不正确,此 JS 将显示警报.我无法访问其来源.我想在我的 UIWebViewDelegate 中处理它.

The target page contain a JS. If user name or password is incorrect this JS show alert. I have not any access to its sources. I want to handle it inside my UIWebViewDelegate.

推荐答案

如果包含 Flash"是指您正在加载到 Web 视图中的页面中包含 Adob​​e Flash 电影,那么您就不走运了, 我耽心.移动版 Safari 不支持 Flash,而且很可能永远不会.

If by "contain a flash" you mean the page you're loading into your web view has an Adobe Flash movie in it, you're out of luck, I'm afraid. Mobile Safari doesn't support Flash, and most likely never will.

在一般情况下,如果您希望在 Web 视图中运行的 JavaScript 与托管它的本机应用程序通信,您可以加载虚假 URL(例如:myapp://alert?The+text+of+the+警报+去+这里.").这将触发 webView:shouldStartLoadWithRequest:navigationType: 委托方法.在该方法中,检查请求,如果正在加载的 URL 是这些内部通信之一,则在您的应用中触发适当的操作,并返回 NO.

In the general case, if you want JavaScript running in a web view to communicate with the native app hosting it, you can load fake URLs (for example: "myapp://alert?The+text+of+the+alert+goes+here."). That will trigger the webView:shouldStartLoadWithRequest:navigationType: delegate method. In that method, inspect the request, and if the URL being loaded is one of these internal communications, trigger the appropriate action in your app, and return NO.

更多推荐

我可以在 UIWebViewDelegate 中处理警报吗?

本文发布于:2023-11-27 23:03:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   UIWebViewDelegate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!