Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. resize iframe to size of contents

resize iframe to size of contents

Scheduled Pinned Locked Moved Web Development
javascriptquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krisp
    wrote on last edited by
    #1

    I would like to resize an iframe to the offsetWidth and offsetHeight of the contents in the iframe. However, It requires me to set a timeout so that the offset sizes can be determined. If I dont set a timeout, it seems that IE has not fully deteremined the offset sizes and therefore the iframe gets sized to be too small. Especially when there are images in the contents of the iframe. But if I wait one second, IE has by then rendered everything and it knows the actual offset sizes of the contents of the iframe. This seems like a horrible way to achieve this functionality. Is there any javascript event that fires once the actual layout has been determined? function ResizePage(WaitASec) { if (window.frameElement) { if (WaitASec) { window.setTimeout("ResizePage(false);", 1000); return; } window.frameElement.style.height = document.getElementsByTagName('div')[0].offsetHeight; window.frameElement.style.width = document.getElementsByTagName('div')[0].offsetWidth; } }

    L 1 Reply Last reply
    0
    • K krisp

      I would like to resize an iframe to the offsetWidth and offsetHeight of the contents in the iframe. However, It requires me to set a timeout so that the offset sizes can be determined. If I dont set a timeout, it seems that IE has not fully deteremined the offset sizes and therefore the iframe gets sized to be too small. Especially when there are images in the contents of the iframe. But if I wait one second, IE has by then rendered everything and it knows the actual offset sizes of the contents of the iframe. This seems like a horrible way to achieve this functionality. Is there any javascript event that fires once the actual layout has been determined? function ResizePage(WaitASec) { if (window.frameElement) { if (WaitASec) { window.setTimeout("ResizePage(false);", 1000); return; } window.frameElement.style.height = document.getElementsByTagName('div')[0].offsetHeight; window.frameElement.style.width = document.getElementsByTagName('div')[0].offsetWidth; } }

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      iframes are inline elements so u cant "redraw" them after the page has drawn ... they are drawn inline period afaik thats why iframes can be tricky to work with


      "there is no spoon"
      biz stuff about me

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups