UIWebView中的Facebook评论框的高度不合适 [英] Facebook Comment box inside UIWebView doesn't have the right height
问题描述
我正在尝试在UIWebView中加载以下html.
I am trying to load the following html inside a UIWebView.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'myAppId',
status : true,
xfbml : true
});
FB.Event.subscribe("xfbml.render", function(response) {
FB.Canvas.setSize();
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-comments" data-href="http://www.google.com/" data-num-posts="10"></div>
</body>
</html>
在浏览器中,它正确显示了注释框,并且FB.Canvas.setSize()适当地调整了高度的大小(如果没有,则iframe的跨度高度将设置为160).
In a browser it displays the comments box correctly and FB.Canvas.setSize() resizing the height appropriately (without it the iframe's span height is set to 160).
此setSize()函数似乎在UIWebView内不执行任何操作,这可能是因为url的方案不是http或https.我无法验证这一点,因为Safari调试器没有显示不安全的Javascript尝试"消息.
This setSize() function appears to do nothing inside of a UIWebView, probably because the scheme of the url is not http or https. I cannot verify this because the Safari debugger doesn't show me the 'Unsafe Javascript attempt' message.
我正在使用loadHTMLString:baseURL:
I am loading the UIWebView with loadHTMLString:baseURL:
如何使Facebook评论框具有合适的高度?
旁注:
类似的问题:无法在iOS UIWebView内加载完整的Facebook注释插件
在Facebook的all.js中乱七八糟,我在注释功能(如果您要查找'sdk.XFBML.Comments')中找到了这段代码,该代码可以设置高度
Mucking around in facebook's all.js I found this code inside the comments function (if you're looking look for 'sdk.XFBML.Comments') that sets the height
getSize: function() {
if (this._attr.mobile) return {
width: '100%',
height: 160
};
return {
width: this._attr.width,
height: 160
};
推荐答案
此处存在相同问题.解决方案是不使用本地HTML文件(或HTML字符串).将HTML文件上传到服务器并使用:
Same problem here. The solution was not to use a local HTML file (or HTML string). Upload the HTML file to an server and use:
NSURL *url = [NSURL URLWithString:@"http://www.blablblab.com/yourfile.html"];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
代替:
[self.webview loadHTMLString:localString baseURL:nil];
我还没有发现为什么文件在服务器上时布局会有差异,但是当它是本地文件时,我的Facebook Comments View的高度始终减小为"height:160".
I didn't discovered yet why there is a difference in the layout when the file is on a server, but when it is a local file, the height of my Facebook Comments View was always reduced to "height:160".
这篇关于UIWebView中的Facebook评论框的高度不合适的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!