在iPhone Webview中使用本地资源 [英] Using local resources in an iPhone webview

查看:52
本文介绍了在iPhone Webview中使用本地资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设某个应用具有一个使用JQuery的Web视图.

Suppose an app has a webview that uses JQuery for example.

服务器为页面提供了适当的链接以加载JQuery,并且视图工作正常,但我希望它不需要下载JQuery(是的,它可以被缓存,但这不是应用程序的第一次运行,我宁愿不要指望它)

The server delivers the page with appropriate links to load JQuery, and the view works fine, but I would like it to not need to download JQuery (yes it may be cached, but it won't be the first time the app runs and I would rather not count on it)

因此,我可以在应用程序中包含JQuery文件,但是该如何嵌入链接?

So I can include the JQuery files with the app, but then how should I embed the links?

服务器当然不知道分发包路径.

The server certainly doesn't know the bundle path.

我以为我可以将URL加载到字符串中,然后在显示在Webview中之前用本地路径替换JQuery路径.

I thought I could load the url into a string and then replace the JQuery paths with the local paths before displaying in the webview.

有没有更简单的方法?

推荐答案

您可以为jQuery使用相对路径,并将baseURL设置为bundle路径.但是,这要求所有资源都在bundle目录中(绝对路径引用的资源除外).

You can use relative paths for jQuery and set the baseURL to the bundle path. However that requires that all resources are in the bundle directory (except those which are referenced by an absolute path).

这篇关于在iPhone Webview中使用本地资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆