I am trying to build a chart into my MacOS app, and decided that rather than using the limited options available in native objective-c, I would be better off using HTML 5, and embedding a WebView control.
I have managed to embed the WebView okay, by linking to an index.html file that is part of my application, using the following.
// Load the HTML content.
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/index.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
I tested this with some simply html, so I know it is connected okay. However, when embedding some more complex code, which includes some CSS and JS, it doesn't render. If I load the index.html
in a safari window, it renders the chart.
Is there something more I have to do to make the Javascript execute?
For extra detail, the chart uses JQPlot, and the content of the index file is...
<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>
Update:
I have carried out more analysis, and I have found I can execute standard javascript, but jQuery is not working. So, I am guessing that the problem is to do with loading of the script tags at the top of the html page.