1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

iframe auto height problem

Discussion in 'JavaScript' started by hallianonline, Dec 8, 2014.

  1. #1
    Hello i am trying to resize the iframe based on its content but its not working may be becuase of the cross domain

    here is the code i am using
        <script language="javascript" type="text/javascript">
        function resizeIframe(obj) {
        obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
        }
        </script>
        <iframe src="http://other_domain_name/get?v=07armilCx5A" frameborder="0" scrolling="no" id="iframe" width="100%" height="300px" onload="javascript:resizeIframe(this);"></iframe>
    Code (JavaScript):

    Please help me how this will be resolved to grab a page in iframe from other domain
     
    hallianonline, Dec 8, 2014 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    You don't -- PRECISELY because being able to do so violates the security policy.

    Though as I keep asking people, when did we get to 1997... after all that's the last time anyone had any business using an iframe, or frames for that matter. You know, it was called HTML 4 STRICT?
     
    deathshadow, Dec 12, 2014 IP
  3. kutchbhi

    kutchbhi Active Member

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    70
    #3
    2 Problems:
    First, the onload event handler simply isn't firing! After a bit of googling it seems it will only fire if the src attribute is set and it actually loads some page (Kind of makes sense, now that I am writing about it )
    Second, for the security problem.. just have a look at the code:
    <body>
    <iframe class="stumble-frame" src="http://fallinprices.com" onload="resizeIframe(this)"></iframe>
           
    <script language="javascript" type="text/javascript">
            function resizeIframe(obj) {
              alert(1);
              obj.style.height =document.body.scrollHeight + 'px';
    
            }
    </script>
    </body>
    Code (JavaScript):
     
    kutchbhi, Dec 15, 2014 IP