#1 09.08.06 15:34
[JavaScript] Получение размеров страницы, подгруженной в iFame
Необходимо изменять размеры iFrame в зависимости от размера страницы, которая в него подгружается.
Для IE всё просто:
Код: javascript:
var iFrame = frames[frameName]; var newHeight = iFrame.document.body.scrollHeight;
Но в остальных браузерах это свойство либо отсутствует, либо равно 0.
Offline
#2 10.08.06 14:19
Re: [JavaScript] Получение размеров страницы, подгруженной в iFame
Всем спасибо. Решение:
Код::
index.html
<html>
<head>
<script type="text/javascript">
function adjustIFrameSize (iframeWindow) {
if (iframeWindow.document.height) {
var iframeElement = document.getElementById(iframeWindow.name);
iframeElement.style.height = iframeWindow.document.height + 'px';
iframeElement.style.width = iframeWindow.document.width + 'px';
}
else if (document.all) {
var iframeElement = document.all[iframeWindow.name];
if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') {
iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
} else {
iframeElement.style.height = iframeWindow.document.body.scrollHeight + 5 + 'px';
iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
}
}
}
</script>
</head>
<body>
<iframe name="iframeName" id="iframeName" marginwidth="0" marginheight="0" src="test.html"></iframe>
<hr>
</body>
</html>
test.html
<html>
<head>
</head>
<body onload="if (parent.adjustIFrameSize) parent.adjustIFrameSize(window);">
...
</body>
</html>Offline

