[英]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>
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.