这个问题听起来很奇怪,但这是我的情况.
The question sounds weird, but here is my case.
我的 UIView
中有一个 UIWebView
(由 [self.view addSubview:webView];
完成),它占据了全屏.它在 UIWebView
点击动作 javascript:window.close();
之前有意隐藏 UIView
.
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 关联到 UIView
的操作,例如[webView removeFromSuperView];
?
How do I associate JavaScript in UIWebView
page to UIView
's action , e.g. [webView removeFromSuperView];
?
这是可能的:
在 url 中使用您自己的方案设置位置,即
Set the location to something with your own scheme in the url, i.e.
document.location.href = "myscheme://DoSomething"
document.location.href = "myscheme://DoSomething"
这将导致 UIWebViewDelegate 方法 shouldStartLoadWithRequest: 使用方案为myscheme"的 NSURLRequest 参数调用.因此,您查找此方案并提取 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:window.close() 关闭 UIWebView;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!