admin管理员组文章数量:1294659
I recently started working on a IOS project that runs mainly on a UIWebView
. Now my UIWebView
is a delegate of UIWebViewDelegate
and what I have encountered is that my app does not respond to window.close
and other window
events that JavaScript
might call. Now I am able to pick up a new HTTP
request shot off through a href
in my shouldStartLoadWithRequest
delegate method.
My hope is to know if there is a way to listen for window
events such as window.close
in my IOS
app and to retrieve the targets. I want to stray away from injecting
any sort of JavaScript
into the page directly as much as possible!
Anyone care to explain if or if not this is possible and why?
I recently started working on a IOS project that runs mainly on a UIWebView
. Now my UIWebView
is a delegate of UIWebViewDelegate
and what I have encountered is that my app does not respond to window.close
and other window
events that JavaScript
might call. Now I am able to pick up a new HTTP
request shot off through a href
in my shouldStartLoadWithRequest
delegate method.
My hope is to know if there is a way to listen for window
events such as window.close
in my IOS
app and to retrieve the targets. I want to stray away from injecting
any sort of JavaScript
into the page directly as much as possible!
Anyone care to explain if or if not this is possible and why?
Share Improve this question asked Aug 5, 2015 at 21:11 David BigaDavid Biga 2,8018 gold badges40 silver badges63 bronze badges2 Answers
Reset to default 4Using UIWebView
there is no way of achieving this without injecting some JavaScript. Even the newer WKWebView
would still need JavaScript injection to make this work.
You would inject JavaScript that would override the window.close
function and trigger a location change with something like location.href = "uniquescheme://window.close";
which, as you say, could be handled in shouldStartLoadWithRequest
.
Something like:
[self.webView stringByEvaluatingJavaScriptFromString:@"window.close = function () { location.href = 'uniquescheme://window.close'; }"]
For WKWebView
there are methods which catch the calls for (implement WKUIDelegate)
window.open
: createWebViewWithConfiguration: forNavigationAction: windowFeatures:
and for
window.close
: webViewDidClose:(WKWebView *)webView NS_AVAILABLE(10_11, 9_0)
mind it, it's only available 9.0 and up.
but not in UIWebView
(actually still investigating if it can be done without injection, will update the answer if I find any)
本文标签: iosHandling Windowclose in JavaScript through UIWebViewObj CStack Overflow
版权声明:本文标题:ios - Handling Window.close in JavaScript through UIWebView - Obj C - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741603253a2387824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论