admin管理员组

文章数量:1315025

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)

本文标签: iosClose UIWebView using javascriptwindowclose()Stack Overflow