0

I use loadHTMLString method to load a HTML string.

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

the html's content like below:

<!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>

The result didn't work well. The javascript code didn't execute. But when I change <script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js"> to a local one and give a proper baseURL, it will work well.

2
  • 1
    Could this be because you are using an http URL to fetch your remote JavaScript? By default, iOS 9 does not do remote http (has to be https). Commented Jan 8, 2016 at 17:45
  • Yes, it's about https. But I test on an iOS 8.4 device, it require https too. Commented Jan 9, 2016 at 12:57

1 Answer 1

1

As @matt mentioned, it's about https.

Remote JavaScript must be a https one. when I change the script to "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js", it worked.

I test it on iOS 9/8.4, UIWebView / WKWebView, they all require https.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.