1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Sitefinity iFrame parent.document.getElementByID not working?

Sitefinity iFrame parent.document.getElementByID not working?

2 posts, 0 answered
  1. Scott MacFarlane
    Scott MacFarlane avatar
    3 posts
    Registered:
    11 Aug 2008
    03 Jun 2011
    Link to this post

    I have a Sitefinity page with a content block that has an iFrame that pulls in a sub-page from another asp.net site.

    I want the iFrame on the Sitefinity page to resize based on the size of the sub-pages content to prevent the clumsy dual scroll bars when the sub-page is very tall.

    The content block iframe is called "dynframe":
    <iframe width="878" height="300" id="dynframe" src="http://subsite.contoso.com" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" vspace="0" hspace="0"></iframe>

    And the sub-sites page contains:

     

     

    <

     

     

    body onload="resizeToContent()">....

     

     

     

     

     

    And has this script block to to the work:

     

     

     

     

    <Rad:RadCodeBlock ID="ResizeContentRadCodeBlock" runat="server">

     

     

     

     

     

    <script type="text/javascript">

     

     

     

     

     

    function resizeToContent() {

     

     

     

     

    if (self == parent) { alert("self=parent!"); return false; }

     

     

     

     

    var x = 0;

     

     

     

     

    var y = this.document.body.scrollHeight;

     

     

     

     

    while (x < y) { x += 1; }

     

     

    alert(

     

    "resizing x=" + x);

     

     

     

     

    var z = parent.document.getElementById('dynframe');

     

     

    alert(

     

    "after z!");

     

     

     

     

    if (z != null) { z.style.height = x; alert("dynframe height: " + x + " -> " + z.style.height); }

     

     

     

     

    else { alert("dynframe not found!"); }

     

     

    }

     

     

     

    </script>

     

     

     

     

     

    </Rad:RadCodeBlock>

     

     

     

     

     


    When the page runs, it always shows the resizing x=? alert with the proper height we are trying to achieve.
    BUT, it never reaches the alert("after z"); at all!
    It's as if the var z = parent.document.getElementById('dynframe');
    is stopping or blocking the script block from continuing, so
    of course the work of setting the iFrame size cannot be done.

    This iFrame resizing seems to be a common practice out there and works perfectly
    other non-sitefinity tests I have tried so I am wondering if Sitefinity is purposely
    blocking this in some way.

    Frustrated, any help would be much appreciated!, Scott

     

  2. Scott MacFarlane
    Scott MacFarlane avatar
    3 posts
    Registered:
    11 Aug 2008
    03 Jun 2011
    Link to this post
    As per usual, you figure it out just a fraction of a second after you give up and ask for help.
    Turns out the getElementbyID was getting an Access Denied (cross-site scripting) Error since
    the iFrame page was in another domain (actually a sub-domain). So that's the problem although
    I don't have an answer yet as I can't seem to get a virtual directory underneath Sitefinity properly
    configured and working as a separate application under IIS 7.5....sigh....
2 posts, 0 answered