【发布时间】:2012-02-27 11:23:57
【问题描述】:
我正在尝试在我的 MacOS 应用程序中构建图表,并决定与其使用本机 Objective-c 中可用的有限选项,不如使用 HTML 5 并嵌入 WebView 控件。
我已经成功地嵌入了 WebView,方法是使用以下链接到我的应用程序中的 index.html 文件。
// Load the HTML content.
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/index.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
我用一些简单的 html 对此进行了测试,所以我知道它连接正常。但是,当嵌入一些更复杂的代码(包括一些 CSS 和 JS)时,它不会呈现。如果我在 Safari 窗口中加载 index.html,它会呈现图表。
要让 Javascript 执行,我还需要做些什么吗?
更多细节,图表使用JQPlot,索引文件的内容是……
<html>
<head>
<script language="javascript" type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />
</head>
<body>
<div id="chartdiv" style="height:200px;width:300px; "></div>
<script>
$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
</script>
</body>
</html>
更新:
我进行了更多的分析,我发现我可以执行标准的 javascript,但是 jQuery 不工作。所以,我猜这个问题与在 html 页面顶部加载脚本标签有关。
【问题讨论】: