UIWebView不能注入HTML
UIWebView can't inject HTML
我试图把一些HTML在一个UIWebView的div。虽然代码看起来是正确的,但它不能工作。
如此:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('"testdiv'").innerHTML = '"Test text here'""]];
这并不:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('"testdiv'").innerHTML = '"%@'"", htmlString]];
在第二种情况下'htmlString'只是一些HTML内的blockquote。
基本上当我用HTML做的时候,它失败了。我的第一个想法是HTML可能是无效的,但我认为它仍然会尝试显示它。
作为操作的结果,我得到的'错误'只是一个空(非nil)字符串。
任何想法?
编辑:下面是一个不显示的HTML示例:
<div style="padding-bottom: 20px;"></div><div><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content=
"text/html charset=us-ascii" />
<title></title>
</head>
<body style=
"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"
class="">
TestTESTEST<br class="" />
<div apple-content-edited="true" class="">
<div style=
"color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"
class="">
<div class="" style="font-size: 10px;"><br class="" /></div>
</div>
</div>
</body>
</html>
</div>
htmlString变量就是blockquote标签中的HTML。
编辑2:
如果我把HTML直接放在文档中,然后加载它,它就可以工作了。只有当我试图通过JS插入它时才会出现问题。
临时解决方案:
由于我要插入的HTML文档只是一个模板我将其复制到代码中并构建整个字符串并将其加载到UIWebView中:
。NSString *s = @"<html><body><div1></div1><div2>%@</div2></body></html>", contentToInsert.
理想情况下,我仍然想要得到这个工作,如果我可以通过JS插入HTML,我可以使用多个HTML模板,只是根据需要将内容放入其中。所以,如果你能找到一个解决方案,请告诉我。
相关文章:
- 正在注入包含JS的HTML
- Meteor:在启动时将html注入客户端文件
- 注入的HTML仅在Dom中解释为字符串
- 在包含脚本的地方注入HTML
- 非侵入性Javascript HTML注入
- 将html注入<李>使用js或jquery
- Electron:将原始html注入BrowserWindow
- Html注入javascript代码
- Javascript 在两次 HTML 注入后停止工作
- 使用 jq 通过 html() 或 append() 将 HTML 注入到另一个元素 注入的元素不能被 jq 访问,但使
- 在没有服务器端资源的情况下将 HTML 注入到 HTML 文档中.(离线)
- 函数在jQuery ajax html注入后不起作用
- 使用JavaScript文件将HTML注入页面
- 使用Jquery的HTML注入
- 如何使用Cordova将HTML注入页面'的InAppBrowser
- 我可以将HTML注入iFrame吗
- jQM:只有一些转换在动态HTML注入后才起作用
- 如何将html注入Angular UI引导弹出窗口
- jQuery html注入列表没有包装
- 如何将html注入iframe,并在jquery-ui对话框中显示