Is there a way to do hidden IFRAMEs?

liunx

Guest
A little background:<br />
I have a page that has certain database items represented in IFRAMEs (one per item) that are reloaded at a periodic rate (say, once every 5 seconds). These "database items" represent a database at the server and we wish to monitor these items as they change in real time without having to reload the entire page. Therefore the reload "pulls" new values onto the screen without having to reload the entire page.<br />
<br />
The question:<br />
The flicker is very noticable, so I thought Id look into a way to have a hidden IFRAME and a visible INPUT type and just have the refreshing done off-screen, then javascript can compare the values and if they have changed, assign the new value to the visible INPUT item.<br />
<br />
Is there a way to create hidden IFRAMEs? I have IE6 , so layers are out. <br />
<br />
Thanks in advance,<br />
Doug<!--content-->Try <iframe style="display:none;"><!--content-->if you use display = none the whole page will be jumping around as the iframe is being removed form the flow and put back in. <br />
How much data are you talking about (fields?)<br />
I would go with dynamic script instead of an iframe.<!--content-->Originally posted by Vladdy <br />
if you use display = none the whole page will be jumping around as the iframe is being removed form the flow and put back in. <br />
<br />
<br />
But why would he want to put the iframe back in? :confused:<br />
And if needed, he could still use CSS, just {visibility:hidden} instead.<!--content-->I just put <IFRAME ..... height=0 width=0> and it works with no side effects.<br />
<br />
I thought for sure Id at least see some artifact but IE does let you do it.<!--content-->If you are not using IFRAMEs to display the returned content, why use them at all:confused: :confused: :confused:<!--content-->Originally posted by Vladdy <br />
If you are not using IFRAMEs to display the returned content, why use them at all:confused: :confused: :confused: <br />
<br />
To reload data from the server without annoying flicker. As I have been able to figure out, there is no way for javascript to reload select information from the server, so I put it in hidden IFRAMEs and reload them at periodic intervals (hidden because the reload would cause visual flicker).<br />
<br />
Then my javascript does a diff on the values of the visible and hidden input pairs and updates the visible one on change. No flicker because the update occurs within javascript as an assignment and is not a clean reload of the frame.<br />
<br />
Is there a better way? I've plowed over books recently and they seem to concur that js cannot communicate with the server. This is like my first JS project ever so Im very green to the client-side stuff. This is the best thing I could think of.<!--content-->books-shmooks:rolleyes: <br />
<br />
Something like this goes on your HTML page:<br />
<br />
...<br />
<script><br />
fields = new Array(0,0....0);<br />
fieldIDs = newArray('Field1','Field2',....,'FieldN');<br />
<br />
scriptNode = null;<br />
<br />
function getUpdate()<br />
{ scriptNode=document.createElement('script');<br />
scriptNode.type='text/javascript';<br />
script.src = 'http://www.yourweb.com/serverscript.asp';<br />
document.getElementsByTagName('head')[0].appendChild(scriptNode);<br />
return;<br />
}<br />
<br />
function updateFields()<br />
{ for(i=0;i<fields.length; i++)<br />
{ if(fields!=newfields)<br />
document.getElementById(fieldIDs).firstChild.nodeValue = newfields;<br />
}<br />
document.getElementsByTagName('head')[0].removeNode(scriptNode);<br />
}<br />
</script><br />
....<br />
<p id="Field1">Field 1 Value goes here</p><br />
.....<br />
<p id="Field2">Field 2 Value goes here</p><br />
....<br />
<br />
<br />
Have your server script construct a js file that would have new values in newfields array and call updateFields() function at the end. The output should look like:<br />
<br />
newfields = new Array(12,134,23,....123);<br />
updateFields();<!--content-->Hey thats pretty cool :) And this solution isn't tied to IEs IFRAME. I tried it and on the second update I get a page error, it dies on the appendChild bit in getupdate.<br />
<br />
Any ideas?<br />
<br />
<br />
<HEAD><br />
<script language="JavaScript"><br />
fields = new Array(0,0,0);<br />
fieldIDs = new Array('Field1','Field2','Field3');<br />
<br />
scriptNode = null;<br />
<br />
function getUpdate()<br />
{ <br />
scriptNode=document.createElement('script');<br />
<br />
scriptNode.type='text/javascript';<br />
scriptNode.src = 'http://www.webdeveloper.com/forum/archive/index.php/newwaysource.htm';<br />
<br />
document.getElementsByTagName('head')[0].appendChild(scriptNode);<br />
<br />
return;<br />
}<br />
<br />
function updateFields()<br />
{ <br />
for(i=0;i<fields.length; i++) {<br />
<br />
if(fields != newfields) {<br />
var element = document.getElementById(fieldIDs);<br />
<br />
if (element.type)<br />
element.value = newfields;<br />
else<br />
element.firstChild.nodeValue = newfields;<br />
}<br />
}<br />
<br />
document.getElementsByTagName('head')[0].removeNode(scriptNode);<br />
}<br />
</script><br />
</HEAD><br />
<br />
<FORM> <br />
<p id="Field1">Field 1 Value goes here</p><br />
<p id="Field2">Field 2 Value goes here</p><br />
<INPUT TYPE="TEXT" id="Field3"><br />
<br />
<INPUT TYPE="BUTTON" onclick="getUpdate();" value="UPDATE"><br />
</FORM><br />
<br />
<br />
<br />
<br />
<br />
My "input" file:<br />
<br />
<br />
newfields = new Array(122,134, 'dork');<br />
updateFields();<!--content-->I got it.... the updateFields routine removes the childnode off of 'head' but it should be 'script'. This makes it work every time, but its confusing:<br />
<br />
Why is the following code working? Do you think there isn't some weirdness when I delete the child off of the script element that was created?<br />
<br />
<br />
creation<br />
scriptNode=document.createElement('script');<br />
document.getElementsByTagName('head')[0].appendChild(scriptNode);<br />
<br />
<br />
deletion<br />
document.getElementsByTagName('script')[0].removeNode(scriptNode);<!--content-->Sorry, my screw up - it was too early in the morning to think straight:<br />
My idea was to delete the script node after it was executed (otherwise you will keep accumulating script nodes in your <head> ;) ). <br />
However I put the deletion part in not a very good point and used the wrong function :o <br />
Here is the improved (and tested this time) script<br />
<br />
<br />
<html><br />
<head><br />
<title>Test Dynamic Update</title><br />
<script type='text/javascript'><br />
fields = new Array(0,0,0);<br />
fieldIDs = new Array('Field1','Field2','Field3');<br />
<br />
scriptNode = null;<br />
<br />
updateNumber = 0;<br />
<br />
function getUpdate()<br />
{ dhead = document.getElementsByTagName('head')[0];<br />
if(scriptNode) dhead.removeChild(scriptNode);<br />
scriptNode=document.createElement('script');<br />
scriptNode.type='text/javascript';<br />
scriptNode.src = 'http://www.webdeveloper.com/forum/archive/index.php/newwaysource.htm';<br />
dhead.appendChild(scriptNode);<br />
return;<br />
}<br />
<br />
function updateFields()<br />
{ for(i=0;i<fields.length; i++)<br />
{ if(fields != newfields)<br />
{ var element = document.getElementById(fieldIDs);<br />
if (element.type) element.value = newfields;<br />
else element.firstChild.nodeValue = newfields;<br />
}<br />
}<br />
updateNumber++;<br />
document.getElementById('un').firstChild.nodeValue = updateNumber;<br />
}<br />
</script><br />
</HEAD><br />
<body><br />
<FORM><br />
<p>Number of updates: <span id="un">0</span> </p><br />
<p id="Field1">Field 1 Value goes here</p><br />
<p id="Field2">Field 2 Value goes here</p><br />
<INPUT TYPE="TEXT" id="Field3"><br />
<br />
<INPUT TYPE="BUTTON" onclick="getUpdate();" value="UPDATE"><br />
</FORM><br />
</body><br />
</html><br />
<br />
<br />
I put the number of updates ticker just for the testing purposes. When you have it debuged and ready to put on a timer, use<br />
<body onload="setInterval('getUpdate()',5000)"><!--content-->Many thanks!<br />
<br />
That makes more sense, and you used <span>, which was a new one to me. Very cool.<!--content-->the solution works fine in firefox etc.<br />
unfortunately it does not in safari, it only shows the values for the first update, then the values dont change any more<br />
does anyone know why?<!--content-->
 
Back
Top