0

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.

Codemwnci
  • 54,176
  • 10
  • 96
  • 129

1 Answers1

0

It turns out that the JS files were being compiled, rather than simply being copied across. I found a similar issue here - iPhone UIWebView local resources using Javascript and handling onorientationChange.

The answer was to go to the Build Phases tab after clicking the main target, and moving the JS files from Compile Sources list to the Copy Bundle Resources list.

Community
  • 1
  • 1
Codemwnci
  • 54,176
  • 10
  • 96
  • 129