WN

WN (https://www.wn.se/forum/index.php)
-   Klientsidans teknologier, design och grafik (https://www.wn.se/forum/forumdisplay.php?f=12)
-   -   ändra iframe-height efter sidans innehåll? (https://www.wn.se/forum/showthread.php?t=3825)

affe_810221 2004-09-24 15:12

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');}"


--------------------------------------------------------------------------------


digiArt 2004-09-24 16:02

Jag har gjort ett inlägg kring detta i ett annat forum

http://www.pellesoft.se/communicate/...x?msgid=127081


Alla tider är GMT +2. Klockan är nu 15:14.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson