簡體   English   中英

Javascript 函數 joomla iframe 自動高度

[英]Javascript function joomla iframe auto height

我在自己的域和 joomla 上托管 iframe! 我已經設置了一個 iframe 包裝器。 我給出的網址以http://www.開頭http://www. 我的設置是:

scroll bars: auto
width: 100%
height: 500

auto height: yes
auto add: no

我的兩個瀏覽器都給我一個 javascript 錯誤(null 不是對象):使用 safari、firefox 和 chrome。 此錯誤指向 joomla 核心中的腳本:

<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>

這使我的包裝器保持在 500px 高度,我希望它根據 iframe 的高度自動添加。

我可以用什么代替這個功能? 提前致謝,洛朗。

試試這個來調整 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>
  1. 將文件 components/com_wrapper/views/wrapper/tmpl/default.php 復制到 templates/your_template/html/com_wrapper/wrapper/
  2. 打開文件模板/your_template/html/com_wrapper/wrapper/default.php
  3. 用下面的新函數替換 iFrameHeight() 函數:
function pageY(elem) {
        return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
    }
    var buffer = 0; //scroll bar buffer
    function iFrameHeight() {
        var height = document.documentElement.clientHeight;
        height -= pageY(document.getElementById('blockrandom'))+ buffer ;
        height = (height < 0) ? 0 : height;
        document.getElementById('blockrandom').style.height = height + 'px';
    }
    document.getElementById('blockrandom').onload=iFrameHeight;
    window.onresize = iFrameHeight;

這段代碼對我不起作用。 但我解決了它:

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').height = the_height;

版本 ps:1.6 版本 joomla:3.2.1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM