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;
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
