Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 50
  1. #31
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Great Code!

    Great Code Sunil! Thanks! It even works perfectly in Chrome. Cheers, Sishab



    Quote Originally Posted by sunilrajkg View Post
    Hi everyone,

    The below code might help you.
    It works well in both Firefox and IE all versions.

    Code:


    function setIframeHeight(iframeName) {
    var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
    if (iframeEl) {
    iframeEl.style.height = "auto";
    // need to add to height to be sure it will all show
    var h = alertSize(iframeName);
    iframeEl.style.height =h + "px";
    }
    }

    function alertSize(frameId) {
    var myHeight = 0;
    frame = document.getElementById(frameId);
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
    var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0;
    myHeight=frame.contentDocument.body.offsetHeight+FFextraHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'

    innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
    myHeight= innerDoc.body.scrollHeight + 10;
    //myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
    }
    //window.alert( 'Height = ' + myHeight );
    return myHeight;
    }



    Iframe tag:

    <iframe id="boardframe" scrolling="auto" name="boardiframe" width="600" frameborder="0" src="http://yourdomain.com/Comments.aspx?id=xxx" onload="setIframeHeight('boardframe');"></iframe>


    Cheers
    Sunil

  2. #32
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question of Frame Resize...

    Hi...

    Continuing on with the thread, I am having a problem with the resize...

    I use the script below to adjust the size of the frame. It works nicely for me. The only problem is, the frame initially jumps to the bookmark, and then on the reload, jumps to the top of the page.

    Any ideas on how to keep the frame at the bookmark in the web page, instead of jumping back up to the top????

    Thanks much in advance....



    <script>
    <!--
    function resize_iframe(){
    if ( window.frames["MainWindow"].document.body.scrollHeight=0 )
    {
    }
    else
    {
    document.getElementById("MainWindow").height=100
    document.getElementById('MainWindow').height=window.frames["MainWindow"].document.body.scrollHeight + 20
    }
    }
    // -->
    </script>



    <IFRAME src="main.htm" frameborder="0" scrolling="no" ID=MainWindow NAME=MainWindow HEIGHT=800 WIDTH=1012 onLoad=resize_iframe();></IFRAME>

  3. #33
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by belboz View Post
    The only problem is, the frame initially jumps to the bookmark, and then on the reload, jumps to the top of the page.
    What causes the iframe to jump on initial load of the parent page?

    Do you mean on reload of the parent page of just the iframe?

  4. #34
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Initial Jump...

    Thanks for taking the time...

    The frame has an image in it, and it links to the next image in a sequence. The link references the same frame (_self), but a new page with a picture on it. The new page has a bookmark #pic so that the page is positioned so the person doesn't have to scroll. Sort of like a point and click slide show.

    photo2.htm#pic

    Is the referencing link.

    When the page does not get reloaded because the frame is referenced from the external site, the page adjusts to the bookmark nicely. It is just that last reload.

    I'm stuck with frames for many reasons. It is what I know, and by framing it, I eliminate the need to make duplicate web pages, which have quite a bit of information on it. The below the line information (framed info) can be used from many different sites, but appears to be a seamless entity.

    Thanks again....

  5. #35
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    And...

    I mean the reload of the parent page, not the frame. When the frame is initially loaded, everything is fine.

    The step when it adjusts the size of the frame based on the height of the information - the purpose of the script.

  6. #36
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    It would be helpful to see this working, however there is an error in the code that may have something to do with the problem.

    The statement if ( window.frames["MainWindow"].document.body.scrollHeight=0 ) is intended as a comparison, but is actually setting the height to 0 prior to setting the correct height.

    Try reducing the code to this:
    Code:
    <script type='text/javascript'>
    
    document.getElementById("MainWindow").height=100
    document.getElementById('MainWindow').height=window.frames["MainWindow"].document.body.scrollHeight + 20
    
    </script>
    Currently this is the code that I recommend for resizing iframes to their content. The example should have the same effect:
    Code:
    <script type='text/javascript'>
    
    function sizeToMyContent( ifRef, setW, setH, fMargin )
    {
     var ifDoc, margin = typeof fMargin === 'number' ? fMargin : 16, h, w, sTop, sLeft;
    
     try
     {
      ifDoc = ifRef.contentWindow.document.documentElement;
     }
     catch( e ){ ifDoc = null; }
    
     if( ifDoc )
     {
      sLeft = document.body.scrollLeft + document.documentElement.scrollLeft;
      sTop = document.body.scrollTop + document.documentElement.scrollTop;
    
      if( setH )
      {
       h = ifDoc.scrollHeight;
       ifRef.height = 1;
       ifRef.height = h + margin;
      }
    
      if( setW )
      {
       w = ifDoc.scrollWidth;
       ifRef.width = 1;
       ifRef.width = w + margin;
      }
     }
    
     window.scrollTo( sLeft, sTop );
    
    }
    
    </script>
    
    <iframe src='myfile.htm' onload='sizeToMyContent(this, false, true, 20);' ></iframe>
    Last edited by Arty Effem; 09-26-2010 at 04:56 PM. Reason: Error

  7. #37
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks,,,

    I'll give it a shot...

    It is at www.ipoverty.com for now....

    Just trying to put something together with limited knowledge, so thanks for pointing out the mistakes....

  8. #38
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for the effort...

    Gave it a shot at www.ipoverty.com

    But it just blew past the bookmark when clicking on the images....

    I see you put some thought into it, so I appreciate it. Unless something obvious stands out, I'll just live with it as it is. Thought it might be something simple....

    Cheers....

  9. #39
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by fasa View Post
    Hello,

    i use AnthonyB script but it doesn't work in Mozilla Firefox 1.5.0.6, when i use function document.getElementById, I receive [null] object, i test it in Explorer 7 and Opera and there it works correctly.

    Can anyone help me?
    are you sure you have assigned an ID, not just a 'name' attribute.

    They are different but IE is IE

    ___________________
    watch movies online

  10. #40
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by belboz View Post
    Gave it a shot at www.ipoverty.com

    But it just blew past the bookmark when clicking on the images....

    I see you put some thought into it, so I appreciate it. Unless something obvious stands out, I'll just live with it as it is. Thought it might be something simple....

    Cheers....
    I have amended the code I gave in post #36. I noticed a problem and also revised it to restore the parent's scrolled position. It's still called in the same way.

  11. #41
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks....

    It works perfectly. I would not have been able to figure it out by myself.

    I appreciate the efforts and hope the good karma is returned to you some day......

    Thanks again....

    Arnold

  12. #42
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Actually..

    I just noticed that the frame size does not contract if it is smaller. That was shy I threw in the If statement above....

    I'll try and throw it back in...

  13. #43
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by belboz View Post
    I just noticed that the frame size does not contract if it is smaller. That was shy I threw in the If statement above....

    I'll try and throw it back in...
    I noticed that in I.E. and Safari. You need a strict doctype at the top of all involved documents:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    There still seems to be an inconsistency when setting width and height together, but I'll look into that.

  14. #44
    New Coder
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sweet...

    It works like a charm. Tripple checked...

    If you are ever in Ann Arbor, MI - drop me a note and I'll buy dinner...

    Thanks,

  15. #45
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Revisit topic

    Quote Originally Posted by belboz View Post
    I just noticed that the frame size does not contract if it is smaller. That was shy I threw in the If statement above....

    I'll try and throw it back in...
    hi,
    sorry to revisit topic, i have tried the code and it partially works for me. however like belboz i have a problem where the frame size does not contract if it is smaller. i have virtual zero experience in javascript so need help. the code i am using is below, can somebody please tell me what to add to it so if the linked frame size is smaller the frame automatically contracts as it only goes bigger at the moment.

    Coded used:

    <html>
    <script type="text/javascript">
    function autoIframe(frameId){
    try{
    frame = document.getElementById(frameId);
    innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
    objToResize = (frame.style) ? frame.style : frame;
    objToResize.height = innerDoc.body.scrollHeight + 15;
    }
    catch(err){
    window.status = err.message;
    }
    }
    </script>


    <body>

    <iframe id="tree" name="tree" src="myitems.htm" onload="if (window.parent && window.parent.autoIframe) {window.parent.autoIframe('tree');}"
    width="860" frameborder="0" >

    </iframe>

    </body>

    </html>

    thanks in advance.


 
Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

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