【发布时间】:2012-02-11 18:34:27
【问题描述】:
我正在尝试使用该函数在 html 页面中调用 javascript -
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()"];
}
这是 html 页面上的 javascript -
<script>
function methodName()
{
// code to draw graph
}
但是,函数methodName() 没有被调用,但是在 window.onload = function () 之后一切正常..
我正在尝试将RGraphs 集成到我的应用程序中,Basic.html 是编写 javascript 的 html 页面。
如果有人能帮我解决这个问题,那就太好了。
【问题讨论】:
-
嘿,如果您不介意,请分享您的示例代码,我可以从本机 iOS 代码调用 rgrpahs 吗?这将非常有帮助。从上周开始,我一直在努力让它发挥作用。
-
我刚刚创建了一个优雅的demo,主题是Javascript在UIWebview中运行,请参考:creiapp.blogspot.hk/2013/04/uiwebview-javascript.html
标签: javascript uiwebview ios5 rgraph