在我的iOS应用中,我想显示包含javascript的HTML。这是一个动画背景。
我设法在WKWebView中显示HTML页面,但不显示javascript背景。 " Hello World"并正确显示页面的背景颜色。
你能帮帮我吗? (我既不知道HTML也不知道Javascript)这是我在Swift中的viewDidLoad:
var webView = WKWebView()
do {
let testHTML = NSBundle.mainBundle().pathForResource("index", ofType: "html")
let contents = try NSString(contentsOfFile: testHTML!, encoding: NSASCIIStringEncoding)
let baseUrl = NSURL(fileURLWithPath: testHTML!) //for load css file
webView.loadHTMLString(contents as String, baseURL: baseUrl)
} catch let error {
print(error)
}
这是我的HTML文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Homepage</title>
<!--Add the new slick-theme.css if you want the default styling-->
<link rel="stylesheet" type="text/css" href="css/home_background.css"/>
</head>
<body class="home", bgcolor="#374283">
<section class="canvas-wrap">
<div class="canvas-content"></div>
<div id="canvas" class="gradient"></div>
</section>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!-- Main library -->
<script src="js/three.min.js"></script>
<!-- Helpers -->
<script src="js/projector.js"></script>
<script src="js/canvas-renderer.js"></script>
<!-- Visualitzation adjustments -->
<script src="js/3d-lines-animation.js"></script>
<!-- Animated background color -->
<script src="js/color.js"></script>
<h1>Hello world!</h1>
</body>
谢谢!