我可以在UIWebViewDelegate中处理警报吗? [英] Can I handle alert inside UIWebViewDelegate?

查看:67
本文介绍了我可以在UIWebViewDelegate中处理警报吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script language="javascript">
    alert("Hell! UIWebView!");
</script>

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

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

更新:

我' m将网页加载到我的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你的意思是你加载到你的网页视图中的页面上有一部Adobe Flash电影,你很运气,我很害怕。 Mobile Safari不支持Flash,很可能永远不会支持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?+ + + + + alert + + here。)。这将触发 webView:shouldStartLoadWithRequest:navigationType: 委托方法。在该方法中,检查请求,如果正在加载的URL是这些内部通信之一,则在您的应用程序中触发相应的操作,并返回

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中处理警报吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆