Close UIWebView using javascript:window.close();

血红的双手。 提交于 2019-12-01 18:21:33

问题


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]; ?


回答1:


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)



来源:https://stackoverflow.com/questions/10843736/close-uiwebview-using-javascriptwindow-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!