【问题标题】:JavaScript with iphoneJavaScript 与 iPhone
【发布时间】:2012-09-28 10:27:34
【问题描述】:

我有一个大问题 我在我的程序中使用 WebView 中的 HTML 和 JavaScript。一切似乎都没有,但当我设置它的路径时,他会看到一个 Java 脚本

但是如果每个人都在 javascript 中放入 html 都可以工作

问:如何正确设置文件 javascript 的路径

我找到了解决方案。这很简单。我的 JavaScript 文件格式错误。如果你在 UTF-8 中做出来,都站在原地 而且添加起来真的很容易

【问题讨论】:

标签: javascript iphone html xcode webview


【解决方案1】:

标准方式是

<script type="text/javascript" charset="utf-8" src="YourJSPath"></script>

【讨论】:

  • 这是正确的,在WebView上连接了我的java脚本,但他拒绝打开它
  • "Kiyura" 提示选项之一,因为他确实在工作,但是我的 java 脚本很大,不太喜欢插入它所以我想链接
【解决方案2】:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file_name" ofType:@"file_type"];  
NSData *data = [NSData dataWithContentsOfFile:filePath];  
if (data) {  
  NSBundle *bundle = [NSBundle mainBundle]; 
  NSString *path = [bundle bundlePath];
  NSString *fullPath = [NSBundle pathForResource:@"file_name" ofType:@"file_type" inDirectory:path];
  [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]];
}

【讨论】:

    【解决方案3】:

    所以,我修复了这个错误。这是用 Javascript Foreman 编写的事实,而不是 UTF-8,据我了解,xCode 仅支持 UTF-8

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多