Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's addJavascriptInterface equivalent in iOS

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?

like image 404
zxcmehran Avatar asked Aug 18 '11 06:08

zxcmehran


2 Answers

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.

like image 151
Evgeny Shurakov Avatar answered Nov 11 '22 08:11

Evgeny Shurakov


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

like image 40
Mike Sprague Avatar answered Nov 11 '22 07:11

Mike Sprague