In WKWebView we can call ObjectiveC/Swift code using webkit message handlers webkit.messageHandlers.<handler>.pushMessage(message).
And this works for IFrames too.
Is there a way to respond to this by calling into the IFrame?
Currently the evaluateJavaScript:
API supports munication only to the main frame.
In WKWebView we can call ObjectiveC/Swift code using webkit message handlers webkit.messageHandlers.<handler>.pushMessage(message).
And this works for IFrames too.
Is there a way to respond to this by calling into the IFrame?
Currently the evaluateJavaScript:
API supports munication only to the main frame.
- 2 if evaluateJavaScript contains only JS function's name and arguments, then the simple idea is to use some JS code in the main frame for proxying into IFrame(s). – Vlad Churakov Commented Feb 2, 2016 at 11:37
3 Answers
Reset to default 2What you need is a JavaScript bridge to IOS take a looik at : http://www.priyaontech./2014/12/native-%E2%80%93-js-bridging-on-ios8-using-wkwebview/ and http://www.joshuakehn./2014/10/29/using-javascript-with-wkwebview-in-ios-8.html
Hope this helps
Here is a real good library for a Javascript bridge (it supports UIWebview
and WKWebview
) : https://github./marcuswestin/WebViewJavascriptBridge
The bridge can be used for native to JS or JS to native munication. They've made quite a good job you should have a look on it.
On web side you have to add some JavaScript code, so that the bridge is present on HTML side, their doc shows a setupWebViewJavascriptBridge
method to add (Read Usage part of their readme).
In the end it up to you wether you add this code directly in the page, or through iOS using evaluateJavaScript
synchronous munication between two different processes is not possible