UIWebView的loadHTMLString方法与在线JavaScript无法很好地协同工作?

时间:2016-01-08 17:39:26

标签: ios uiwebview wkwebview

我使用loadHTMLString方法加载HTML字符串。

self.webview.loadHTMLString("the html", baseURL:nil)

html的内容如下:

<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js">
</script>
<script>
$(document).ready(function(){
    $("p").click(function(){
        $(this).hide();
    });
});
</script>
</head>
<body>
<p> Tap me to hide</p>
</body>
</html>

结果并不顺利。 javascript代码没有执行。但是,当我将<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js"> 更改为本地baseURL并提供正确的{{1}}时,它会正常运作。

1 个答案:

答案 0 :(得分:0)

正如@matt所提到的,它是关于https

远程JavaScript必须是https个。当我将脚本更改为"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"时,它可以正常工作。

我在iOS 9 / 8.4,UIWebView / WKWebView上测试它们都需要https