...

View Full Version : Dynamic Content with Iframe - Speedup possible?



resander
08-07-2002, 11:27 AM
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>

Roy Sinclair
08-07-2002, 05:29 PM
<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.

resander
08-08-2002, 02:46 AM
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.

Roy Sinclair
08-08-2002, 07:15 PM
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.

resander
08-10-2002, 01:56 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum