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.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Content with Iframe - Speedup possible?

    I am using:

    1. a tiny external html file ifrm0.htm containing an empty div only
    2. an iframe using the tiny htm as src value.

    The browser would have fetched the tiny htm file from the server when loading the
    iframe. Cost: one round-trip to the server.
    Once the iframe is there, I can fill the div in it with dynamic content using
    innerHTML, as many times as I like without suffering any round-trip delays.
    Is there a way to eliminate the first round-trip and to do all processing
    locally in the browser (some trickery with src, javascript: and evals maybe)? or, is
    there some other way to do it? Scrollbar needed.

    The tiny html file:
    <html>
    <head>
    <title>iframe0</title>
    </head>
    <body>
    <div id="ifrm0"></div>
    </body>
    </html>

    The page with the iframe:
    <html>
    <head>
    <title>Dynamic Content with Iframe</title>
    <script language="JavaScript1.2">
    var n =0;
    var a=new Array('A', 'B','C');
    function setiframe() {
    var o=window.frames[0].document.getElementById('ifrm0');
    var base=n*6;
    var btn='<input id="but" type="button" value="Btn['+a[n]+']" onclick="parent.clik(this)">';
    var s="<html><head><title>Tests</title><\head><body>"+base+"<br>"+(base+1)+"<br>" + btn ;
    s += "<br>"+(base+2)+"<br>"+(base+3)+"<br>"+(base+4)+"<br>"+(base+5)+"</body></html>" ;
    o.innerHTML=s;
    n++;
    if ( n == 3 ) n=0;
    }
    function clik(obj) {
    alert("CLICKED: btnid="+obj.id);
    }
    </script>
    </head>
    <body>
    <iframe id="frameid" src=ifrm0.htm width=100 height=100 frameborder=1
    style="position:absolute;left:150;top:150" scrolling=yes></iframe>
    <p>
    <form method="POST" >
    <input type="button" value="Set Fresh Dynamic Content" onclick="setiframe()">
    </form>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <html> 
    <head> 
    <title>Dynamic Content with Iframe</title> 
    <script language="JavaScript1.2"> 
    var n =0; 
    var a=new Array('A', 'B','C'); 
    function setiframe() { 
    var o=window.frames[0] 
    var base=n*6; 
    var btn='<input id="but" type="button" value="Btn['+a[n]+']" onclick="parent.clik(this)">'; 
    var s="<html><head><title>Tests</title><\head><body>"+base+"<br>"+(base+1)+"<br>" + btn ; 
    s += "<br>"+(base+2)+"<br>"+(base+3)+"<br>"+(base+4)+"<br>"+(base+5)+"</body></html>" ; 
    o.document.open();
    o.document.write (s);
    o.document.close();
    n++; 
    if ( n == 3 ) n=0; 
    } 
    function clik(obj) { 
    alert("CLICKED: btnid="+obj.id); 
    } 
    </script> 
    </head> 
    <body> 
    <iframe id="frameid" src=ifrm0.htm width=100 height=100 frameborder=1 
    style="position:absolute;left:150;top:150" scrolling=yes></iframe> 
    <p> 
    <form method="POST" > 
    <input type="button" value="Set Fresh Dynamic Content" onclick="setiframe()"> 
    </form> 
    </body> 
    </html>
    This should do it.

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Content in Iframe - Speedup possible?

    Thanks for your suggestion.
    I tried o.document.open();o.document.write (s);o.document.close(); , but it didn't work. IE came up with 'unspecified' error and the NS6 Javascript Console reported 'o.document has no properties'.

    Since I wrote the initial post I have tried to simulate a src data source. For example like this:

    function befilecontent() {
    var s="<html><head><title>Tests</title><\head><body>Hello</body></html> ;
    return s ;
    }

    and then put src=javascript:befilecontent() in the iframe tag. It doesn't work.
    I am beginning to think it may not be possible and that the browser needs a real file
    as src value. But, again, if someone can crack this, please let us know.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tested what I posted and it works fine except that the src= property should be removed from the iframe. When you tried it you must have tried editing what I did into some other page rather than simply trying what I wrote.

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Content in Iframe - speedup possible?

    Oops, your diagnosis is spot on. I moved the three document lines into
    my original code, but forgot to change the variable to the frame object
    (it was still left as the div object in the frame).

    I have certainly strayed off along a tangent on this trying to make
    innerHTML work. The frame document write was right under my nose, but
    I didn't see it. 'Toodai no motokurashi' (Jap. proverb = 'The darkness
    at the foot of the lighthouse'.

    What you suggested is exactly what I was after.
    Again many thanks.


  •  

    Posting Permissions

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