当前位置:   article > 正文

java webkit_window.webkit in Typescript

window.webkit.messagehandlers.callbackhandler.postmessage

I guest you are using webView if you not forget window.webkit . You must define it first , by default there is no object (in window):

window.webkit

Just add it :

let contentController = self.webView.configuration.userContentController

contentController.addScriptMessageHandler(self, name: "callbackHandler")

let config = WKWebViewConfiguration()

config.userContentController = contentController

let webView = WKWebView(frame: CGRect.zero, configuration: config)

// Add callback func

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {

// message.name is "callbackHandler"

// message.body is ["programming":"js"]

}

Now you can call in your browser env :

var message = {'programming':'js'};

window.webkit.messageHandlers.callbackHandler.postMessage(message);

Reference :

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/867055
推荐阅读
相关标签
  

闽ICP备14008679号