最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Native -> JS communication in WKWebView IFrames - Stack Overflow

programmeradmin1浏览0评论

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.

Share Improve this question asked Jan 28, 2016 at 21:54 shreyasvashreyasva 13.6k26 gold badges82 silver badges103 bronze badges 1
  • 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
Add a ment  | 

3 Answers 3

Reset to default 2

What 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

发布评论

评论列表(0)

  1. 暂无评论