gpt4 book ai didi

javascript - UIWebView 不加载外部 JavaScript 文件

转载 作者:技术小花猫 更新时间:2023-10-29 11:46:43 25 4
gpt4 key购买 nike

我有以下看似无害的代码 (index.html),但它不会加载 code.js 文件。如果我将文件的内容复制/粘贴到 HTML 页面中,效果会很好。 index.htmlcode.js 文件都在同一目录中。

index.html:

<html>
<head>
<script type="text/javascript" src="code.js"></script>
</head>
<body onload="drawImage()">
<div><canvas id="canvas" width="320" height="480"></canvas></div>
</body>
</html>

ViewController.m:

- (void)viewDidLoad {
[super viewDidLoad];
// load the first webpage
[homePageWebView loadRequest:[NSURLRequest requestWithURL:[NSURLfileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"index"ofType:@"html"] isDirectory:NO]]];
}

最佳答案

我发现Xcode认为js文件需要编译。

在 Xcode 中打开项目。转到“目标”并查看“编译源”。如果您在该文件夹中看到您的 js 文件,请将其移至“Copy Bundle Resources”文件夹并将其从“Compile Sources”文件夹中删除。

如果已安装用于测试的应用程序,请从您的 iPhone 中删除该应用程序。转到 Xcode 中的构建菜单并清除所有目标。然后重新编译。

现在检查您的 HTML 文件是否真的能看到您的 js 文件。

琳达

关于javascript - UIWebView 不加载外部 JavaScript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3606272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com