Close UIWebView using javascript:window.close();(使用 javascript:window.close() 关闭 UIWebView;)
问题描述
这个问题听起来很奇怪,但这是我的情况.
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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 javascript:window.close() 关闭 UIWebView;


基础教程推荐
- :hover 状态不会在 iOS 上结束 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01