PDA

View Full Version : can you have a constant load?



barkermn01
Mar 16th, 2008, 12:51 AM
i have a system the reloads the iframe page every 2 seconds

is there a way i can have javascript keep reloading the page with out making the reloading sound and allways reloading the page

And what i meen is
http://barkersmedia.co.uk/IM/chat.php?From=AdminB&User=AdminA

I need a way for the iframe to silently reload int he page or contantly reload any help if not in javascript another web programing that can do it would help

mjlorbet
Mar 16th, 2008, 01:48 AM
function ReloadSection(){
var myReq = new XMLHttpRequest();
myReq.open("get", "location", false); //change location to the location of the data you want, keep in mind to use ajax it needs to be local or you need to use an http proxy
myReq.send("");
var dataSection = document.getElementById("your_data_containingSection"); //This is not the proper way to access an iframe, but you could make the iframe a div & everything will be ok (style in scrolling if needbe, or just find the correct way to get the contents of an iframe)
while(dataSection.children.length > 0)
dataSection.removeChild(dataSection.children[0]);
dataSection.innerHTML = myReq.responseText;
}

setTimeout("ReloadSection()", 2000);


Is a rough explaination of one way to do it, definately needs buffing out

barkermn01
Mar 16th, 2008, 02:02 AM
Will this work to check the Browser type and then work with it

function ReloadSection()
{var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!"); return false; } } }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);
var dataSection = document.getElementById("your_data_containingSection"); //This is not the proper way to access an iframe, but you could make the iframe a div & everything will be ok (style in scrolling if needbe, or just find the correct way to get the contents of an iframe)
while(dataSection.children.length > 0)
dataSection.removeChild(dataSection.children[0]);
dataSection.innerHTML = xmlHttp.responseText;
}

And in xmlHttp.open("GET","time.asp",true); how do i do it can i

xmlHttp.open("get","view.php",true);

view.php - is what has the text box and pull the SQL information
the iframe loads view.php

The view.php uses information from the GET
view.php?From=AdminA&User=AdminB

and i would add that into the page with php like so
echo 'view.php?From='.$FROM.'&User='.$USER.'';

Would this work

i need this to stay in the textbox so that it can be fixed fast

mjlorbet
Mar 16th, 2008, 02:14 AM
no, like i said, document.getElementById("iframe") isn't the proper way of accessing the iframe.... it's something like window.frames[iframe_id].document.getElementById("textboxname").... although i'm not 100% on the exact proper syntax. also, the xmlhttprequest object does not talk to databases, it talks to pages (php, asp, html, etc.) for a script to talk directly to your databse, you would need to create an activex control that likely instantiated an odbc driver.... much more work than it's worth. you can actually load the contents of a page into a div



<div id="former_iframe" style="overflow:auto; width:##px; height:##px;"></div>

<script type="text/javascript">
function ReloadSection(){
var myReq = new XMLHttpRequest();
myReq.open("get", "location", false); //change location to the location of the data you want, keep in mind to use ajax it needs to be local or you need to use an http proxy
myReq.send("");
var dataSection = document.getElementById("former_iframe");
while(dataSection.children.length > 0)
dataSection.removeChild(dataSection.children[0]);
dataSection.innerHTML = myReq.responseText;
}

setTimeout("ReloadSection()", 2000);
ReloadSection();
</script>


you would just replace location with the actual uri of the page being loaded by your iframe currently. as far as assigning to a textbox within the div, all you have to do i get the textbox by it's id (document.getElementById()). you don't need to get that from the element that it's contained in (if you try to you'll get an error, only the document element has that method, the rest have getElementsByTagName() which returns an array of elements matching a specific tag, in this instance you would want to use document.getElementById("former_iframe").getElementsByTagName("input") to return the list of all input elements within that div)