Javascript函数joomla iframe auto height

Javascript函数joomla iframe auto height,javascript,function,iframe,joomla,height,Javascript,Function,Iframe,Joomla,Height,我在自己的域名和joomla上托管了一个iframe!我已经设置了一个iframe包装器。 我提供的url以http://www.和我的设置是: scroll bars: auto width: 100% height: 500 auto height: yes auto add: no 我的两个浏览器都会给我一个javascript错误(null不是一个对象):使用safari、firefox和chrome。 此错误指向joomla core中的脚本: <script type="t

我在自己的域名和joomla上托管了一个iframe!我已经设置了一个iframe包装器。 我提供的url以
http://www.
和我的设置是:

scroll bars: auto
width: 100%
height: 500

auto height: yes
auto add: no
我的两个浏览器都会给我一个javascript错误(null不是一个对象):使用safari、firefox和chrome。 此错误指向joomla core中的脚本:

<script type="text/javascript">
function iFrameHeight() {
    var h = 0;
    if (!document.all) {
        h = document.getElementById('blockrandom').contentDocument.height;
        document.getElementById('blockrandom').style.height = h + 60 + 'px';
    } else if (document.all) {
        h = document.frames('blockrandom').document.body.scrollHeight;
        document.all.blockrandom.style.height = h + 20 + 'px';
    }
}
</script>

函数iframehight(){
var h=0;
如果(!document.all){
h=document.getElementById('blockrandom').contentDocument.height;
document.getElementById('blockrandom')。style.height=h+60+'px';
}else if(document.all){
h=document.frames('blockrandom')。document.body.scrollHeight;
document.all.blockrandom.style.height=h+20+‘px’;
}
}
这使我的包装保持在500px的高度,我希望它能够根据iframe的高度自动添加

我可以用什么替换此函数?
提前感谢,laurent。

请尝试调整iframe的大小,包括iframe的所有元素都应设置100%的高度

<script type="text/javascript">
$(document).ready(function() {
   function iSize(){
document.getElementById('mainFrame').height = document.getElementById('mainFrame').contentWindow.document.body.scrollHeight;
document.getElementById('mainFrame').height = document.getElementById('mainFrame').contentDocument.documentElement.scrollHeight;
   }
});
</script>

$(文档).ready(函数(){
函数iSize(){
document.getElementById('mainFrame').height=document.getElementById('mainFrame').contentWindow.document.body.scrollHeight;
document.getElementById('mainFrame')。高度=document.getElementById('mainFrame')。contentDocument.documentElement.scrollHeight;
}
});
  • 将文件components/com_wrapper/views/wrapper/tmpl/default.php复制到 模板/your_模板/html/com_包装器/wrapper/
  • 打开文件templates/your_template/html/com_wrapper/wrapper/default.php
  • 将函数iframehight()替换为以下新函数:
  • 功能页(元素){
    返回elem.offsetParent?(elem.offsetTop+pageY(elem.offsetParent)):elem.offsetTop;
    }
    var缓冲区=0//滚动条缓冲区
    函数iframehight(){
    变量高度=document.documentElement.clientHeight;
    高度-=pageY(document.getElementById('blockrandom'))+缓冲区;
    高度=(高度<0)?0:高度;
    document.getElementById('blockrandom')。style.height=height+'px';
    }
    document.getElementById('blockrandom')。onload=iFrameHeight;
    window.onresize=iframehight;
    
    此代码对我不起作用。但我决定:

    var the_height = document.getElementById('blockrandom').contentWindow.document.body.scrollHeight;
    document.getElementById('blockrandom').style.height = the_height; //height + 'px'; 
    
    对不起,正确的线路: var the_height=document.getElementById('blockrandom').contentWindow.document.body.scrollHeight; document.getElementById('blockrandom')。高度=_高度

    ps版本:1.6
    joomla版本:3.2.1

    否,用您的函数替换当前函数不起作用,joomla不允许您在高度字段中输入百分比……您是否重命名了iframe以适应该函数?”“mainFrame”是iframe ID。是的,控制台显示:“找不到变量
    iFrameHeight
    ”(我尝试将函数iSize更改为iFrameHeight,但不执行任何操作),“
    undefined
    不是函数,正在评估
    $(文档)。准备好了吗
    ”请检查我的后期编辑,以及其他可能的解决方案。希望能有帮助。好吧,我通过每个增加几个像素来解决这个问题,但现在它使我所有的iFrame都非常大
    var the_height = document.getElementById('blockrandom').contentWindow.document.body.scrollHeight;
    document.getElementById('blockrandom').style.height = the_height; //height + 'px';