Android's addJavascriptInterface equivalent in iOS

邮差的信 提交于 2019-12-04 18:42:55

问题


As you may know, Android's WebView has a method named addJavascriptInterface() which imports an Android JAVA object to Javascript context.

the question is, Is there any equivalent of it on iOS?


回答1:


UIWebView on iOS doesn't have methods to add interface to DOM.
But you still can talk to your code from javascript assigning something to window.location and handling that request in webView:shouldStartLoadWithRequest:navigationType: delegate method.




回答2:


I know this question is really old, but it seems that there is a better way to do it now with a WKWebView. See this answer: https://stackoverflow.com/a/37373745/1417922



来源:https://stackoverflow.com/questions/7103159/androids-addjavascriptinterface-equivalent-in-ios

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