我在我的网站上使用了 disqus,并添加了一个按钮来显示/隐藏评论。该按钮在 Chrome、Opera(我猜是 IE)上工作正常,但在 Firefox 上失败。
它失败了,因为当我点击按钮时,我没有显示带有评论的 div。 div 似乎没有大小。如果我更改窗口浏览器大小......\°/ 我看评论!为什么 ?
<p id="commentsButton">
<button id="buttonComment" onclick="toggleComments()">
Commentaires</button>
</p>
<script type="text/javascript">
function toggleComments(){
if (document.getElementById("comments").style.display == "none"){
document.getElementById("comments").style.display="inline";
} else {
document.getElementById("comments").style.display="none";
}
}
</script>
好像disqus ifame有风格
style="height: 0px !important
我能做什么?
最佳答案
当 Disqus 加载到隐藏元素中时,Firefox(和某些版本的 IE)会出现古怪的行为。您可以通过将 Disqus 嵌入代码包装在 toggleComments()
函数中来解决此问题,以便在该元素可见时加载它。
不过,请确保将配置变量(例如 disqus_shortname
)保留在函数之外。总而言之,它看起来像这样:
<script type="text/javascript">
var disqus_shortname='YOUR_SHORTNAME';
function toggleComments(){
if (document.getElementById("comments").style.display == "none"){
document.getElementById("comments").style.display="inline";
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}
else {
document.getElementById("comments").style.display="none";
}
}
}
</script>
关于javascript - 显示/隐藏 disqus 按钮不能与 firefox 一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19344258/