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;


基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01