[英]Firefox iframe scrolling issue
我有一個在iframe中托管的網頁。 我只能修改此頁面,而不能修改包含頁面。
默認情況下,頁面的滾動條是禁用的,但是,如果頁面的大小超過某個閾值,則需要能夠打開垂直滾動條。 以下代碼似乎適用於除Firefox之外的所有瀏覽器:
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
function setScrollbar() {
if (getDocHeight() > 5000) {
pageBody.style.overflow = 'scroll';
}
}
這是我的HTML:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>My title</title></head>
<body id="pageBody" onload="setScrollbar();">
</body>
</html>
Firefox似乎忽略了style.overflow ='scroll'。 我已經做了很多搜索,但似乎找不到解決方案。 有任何想法嗎?
替換為:
pageBody.style.overflow = 'scroll';
有了這個:
document.getElementById('pageBody').style.overflow = 'scroll';
當我在FF中檢查了您的代碼時,我收到JS錯誤pageBody未定義,這應該可以解決此問題:)
干杯
G。
style.overflow = 'auto'
應該更好。 它使瀏覽器自己決定何時添加滾動條。
不幸的是,Firefox根據框架上的溢出樣式而不是主體上的溢出樣式在框架主體上顯示滾動條。 因此,最簡單的方法是插入100%大小的無邊界可滾動子幀,然后在其中加載實際內容。
如果您不想這樣做,則可以像這樣嵌套嵌套的DIV:
<body style="margin: 0px;"> <!-- override default body margin -->
<div style="height: 100%; overflow: auto;"> <!-- The actual scrollable area -->
<div style="margin: 8px;"> <!-- to emulate default body margin -->
<!-- Content goes here -->
</div>
</div>
</body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.