SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Auto adjust iFrame to the webpage it's on?

    Hello, I'd like to make an iframe that will automatically get the height of the webpage it is on (not the source url) - I'm not talking the browser viewport but the entire document - so basically the height in pixels minus a certain value to prevent the iframe from sliding out - example:
    Code:
    <iframe src="http://google.com/" height="CURRENT DOCUMENT'S HEIGHT MINUS 50" width="FIXED"></iframe>
    Maybe it is better to achieve this function in php - or any other way? And perhaps there is some better way than an iframe - like a container of some sort that can automatically expand to the webpage's length...

    Thanks in advance!

  2. #2
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This isn't possible using only JavaScript due to the Same Origin Policy.. unless of course you are trying to automatically size an iframe to be the height and width attributes of a page that is on YOUR domain. Is that the case?

    If the page is on a different domain, e.g. Google.com, then you can't get any elements or attributes of the page using Javascript through an iframe. You can always use PHP cURL or something to actually HTTP GET the HTML on the page, and then alter the iFrame using what you HTTP GOT.

  3. #3
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, already solved it.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •