UIWebView中的iOS loadHtmlString不适用于Javascript [英] iOS loadHtmlString in UIWebView doesn't work with Javascript
问题描述
我有一个iOS应用程序,用于加载引用同一目录中的外部CSS文件和javascript文件的html字符串.
I have a iOS app to load a html string which refer to external css file and javascript file in the same directory.
这是我的html文件:
Here is my html file:
<html>
<head>
<meta name="viewport" content= user-scalable="no", width="device-width" />
<meta http-equiv="Content-Type" content="text/html"; charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<script type="text/javascript" src="myjavascript.js"></script>
</head>
css文件工作正常,但似乎js文件从未加载过.可能是什么原因?
The css file works fine but it seems the js file never loaded. What could be the reason?
通过我使用loadHtmlString的方式:BaseUrl方法加载我的html字符串.
By the way I'm using loadHtmlString: BaseUrl method to load my html string.
谢谢
推荐答案
这个问题有点老了,但是由于尚未得到解答,我想指出的是,如果您希望Web视图中加载JavaScript,驻留在您的捆绑软件中的文件,方法是:
This question is a bit old, but since it has not been answered, I would like to point out that if you would like your web view to load a javascript file residing in your bundle, the way to do it is:
[webView loadHTMLString:html
baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
如果您未指定baseURL,则将不会加载javascript文件.
If you don't specify the baseURL there is no chance that the javascript file is loaded.
这篇关于UIWebView中的iOS loadHtmlString不适用于Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!