最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - Close UIWebView using javascript:window.close(); - Stack Overflow

programmeradmin3浏览0评论

The question sounds weird, but here is my case.

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();.

How do I associate JavaScript in UIWebView page to UIView's action , e.g. [webView removeFromSuperView]; ?

The question sounds weird, but here is my case.

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();.

How do I associate JavaScript in UIWebView page to UIView's action , e.g. [webView removeFromSuperView]; ?

Share Improve this question edited Jul 22, 2013 at 14:35 Cezar 56.4k19 gold badges87 silver badges87 bronze badges asked Jun 1, 2012 at 2:39 RaptorRaptor 54.3k47 gold badges246 silver badges399 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

This is possible:

Set the location to something with your own scheme in the url, i.e.

document.location.href = "myscheme://DoSomething"

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.

(In the UIWebView dealloc probably need to make sure you call stopLoading)

发布评论

评论列表(0)

  1. 暂无评论