美文网首页iOS 进阶
WKWebView---evaluateJavaScript

WKWebView---evaluateJavaScript

作者: 初灬终 | 来源:发表于2018-12-07 23:06 被阅读12次
<!DOCTYPE html>
<html>
<head>
    <title>webView</title>
    <script type="text/javascript">
        function showAlert() {
            alert("helloworld");
        }
    </script>
</head>
<body>
    <button onclick="showAlert()">showAlert</button>
</body>
</html>

这里可以调用自定义的js方法,也可以直接使用js语句

[_webView evaluateJavaScript:@"showPrompt()" completionHandler:^(id _Nullable obj, NSError * _Nullable error) {

}];

[_webView evaluateJavaScript:@"alert('helloworld');" completionHandler:^(id _Nullable obj, NSError * _Nullable error) {

}];
image.png

相关文章

网友评论

    本文标题:WKWebView---evaluateJavaScript

    本文链接:https://www.haomeiwen.com/subject/rnhfhqtx.html