L'appel Javascript à l'aide de UIWebView

Je suis en train d'appeler un script javascript dans une page html à l'aide de la fonction -

View did load function
{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"BasicGraph.html"];
    NSURL *urlStr = [NSURL fileURLWithPath:writablePath];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *myPathInfo = [[NSBundle mainBundle] pathForResource:@"BasicGraph" ofType:@"html"];
    [fileManager copyItemAtPath:myPathInfo toPath:writablePath error:NULL];

    [graphView loadRequest:[NSURLRequest requestWithURL:urlStr]];
}

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    [graphView stringByEvaluatingJavaScriptFromString:@"methodName()"];
}

Voici le code javascript dans la page html -

<script>
    function methodName()
      {
         //code to draw graph
      }

Cependant, la fonction methodName() n'est pas appelé, mais une fois la fenêtre.onload = function () tout fonctionne bien..

Je suis en train d'intégrer RGraphs dans mon application et Basic.html est la page html dans laquelle les javascripts sont écrits.

Ce serait génial si quelqu'un pouvait m'aider à sortir de ce.

  • Hey, si ça ne vous dérange pas pouvez vous s'il vous plaît partagez votre exemple de code où je peux appeler rgrpahs de native iOS code? Il sera très utile. depuis une semaine j'ai du mal à le faire fonctionner.
  • Je viens de créer une élégante démonstration sur le thème de Javascript exécuté dans UIWebview, veuillez vous référer à :creiapp.blogspot.hk/2013/04/uiwebview-javascript.html
InformationsquelleAutor learner2010 | 2012-01-16