所以我想弄清楚将javascript文件加载到webview .html文档的路径是什么?
基本上,我试图通过webview的stringByEvaluatingJavascriptFromString方法执行此操作,并传入将脚本元素附加到当前页面的javascript,并将此脚本加载到设备应用程序包的文件中。
到目前为止我尝试的是:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"s=document.createElement('script');s.src='%@';document.body.appendChild(s);", [NSString stringWithFormat:@"%@/file.js", [[NSBundle mainBundle] resourcePath]]]];
我知道webview的附加javascript的方法是可行的,因为我可以通过http://路径加载脚本而没有问题,我只是很难获得我的应用程序资源中的file.js的正确路径。 / p>
有什么想法吗?
答案 0 :(得分:0)
NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle bundlePath];
这为您提供了捆绑包的路径。从那以后,您可以浏览文件夹结构。