Tja!
Vill göra så att en iframe på min sida ändrar sin storlek i vertikal-led efter innehållet i iframen.
Har hittat en del javascript som påstår sig lösa det hela men problemet med dessa är att när jag klickar vidare från den förlängda iframen så ändras inte dennes storlek neråt utan bara uppåt (om det behövs). Vad jag vill ha är ett script som även justerar höjden neråt, dvs när innehållet på sidan blir mindre.
Nånn som redan hittat bättre fungerande script eller förstår hur man kan lösa problemet?
Det här är vad jag använder:
Kod:
--------------------------------------------------------------------------------
//i head'en på sidan med iframen
function resizeIframe(id) {
try {
frame = document.getElementById(id);
// Get the document within the frame. This is where you will fail with 'permission denied'
// if the document within the frame is not from the same domain as this document.
// Note: IE uses 'contentWindow', Opera uses 'contentDocument', Netscape uses either.
innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
// Resize the style object, if it exists. Otherwise, resize the frame itself.
objToResize = (frame.style) ? frame.style : frame;
// Resize the object to the scroll height of the inner document body. You may still have
// to add a 'fudge' factor to get rid of the scroll bar entirely. With a plain-vanilla
// iframe, I found Netscape needs no fudge, IE needs 4 and Opera needs 5...
// Of course, your mileage may vary.
objToResize.height = innerDoc.body.scrollHeight + 5;
}
catch (e) {
window.status = e.message;
}
}
--------------------------------------------------------------------------------
// i body-taggen till sidan som laddas i iframen
onload="if (window.parent && window.parent.resizeIframe) {window.parent.resizeIframe('myFrame');}"
--------------------------------------------------------------------------------