使用javascript关闭UIWebView:window.close(); [英] Close UIWebView using javascript:window.close();
问题描述
这个问题听起来很奇怪,但这是我的理由。
The question sounds weird, but here is my case.
我的<$中有一个 UIWebView
c $ c> UIView (由 [self.view addSubview:webView];
完成)占据全屏。它故意隐藏 UIView
之前 UIWebView
点击动作 javascript:window.close( );
。
I have a UIWebView
in my UIView
( done by [self.view addSubview:webView];
) which occupies full screen. It intentionally hides the UIView
before the UIWebView
clicks on an action javascript:window.close();
.
如何将 UIWebView
页面中的JavaScript与<$ c相关联$ c> UIView 的动作,例如 [webView removeFromSuperView];
?
How do I associate JavaScript in UIWebView
page to UIView
's action , e.g. [webView removeFromSuperView];
?
推荐答案
这是可能的:
在网址中将位置设置为您自己的方案,即
Set the location to something with your own scheme in the url, i.e.
document.location.href =myscheme :// DoSomething
document.location.href = "myscheme://DoSomething"
这将导致使用NSURLRequest参数调用UIWebViewDelegate方法shouldStartLoadWithRequest:其参数为myscheme。因此,你寻找这个方案并提取DoSomething然后对DoSomething采取行动,在你的情况下将从superView调用remove。
This will cause the UIWebViewDelegate method shouldStartLoadWithRequest: to be called with an NSURLRequest parameter whose scheme is"myscheme". So you look for this scheme and extract the DoSomething and then act on the DoSomething, which in your case would be to call remove from superView.
(在UIWebView dealloc中可能需要确保你调用stopLoading)
(In the UIWebView dealloc probably need to make sure you call stopLoading)
这篇关于使用javascript关闭UIWebView:window.close();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!