Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to refresh main page and the contents of a iframe in one shot.

Status
Not open for further replies.

dotolee

Technical User
Jan 27, 2008
134
CA
hi there. i have an asp page that is using the winhttprequest object to get the contents of an "external" website (just a page from another department here.. but a different server).

Then i modify the html i get to suit my needs.. save it to a file, and then finally, i display this stuff in an IFRAME.

(i wrapped a div tag around the iframe so technically, i'm doing something like: "divtabframe.innerHTML = '<IFRAME
SRC='myserver/somepage.html'></IFRAME>)

My problem is that when i refresh the main page, i want the iframe to also display the latest data. It does get the latest data from the external site and its saved in "somepage.html". But the iframe isn't updated unless i explicitly right-click inside the frame and manually select refresh.
I have added a <meta http-equiv="refresh" content="30"> line to make it auto refresh on it's own.
But the users find it annoying that the page refreshes while they're working on it. They prefer to have their own button that will refresh both the main page that gets the data, and the iframe to read the new file.
does anyone have any suggestions?
 
Code:
document.getElementById(FrameID).contentWindow.location.reload(true);

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Chris, thanks for your reply. last night, i found some similar code elsewhere and tried it but i'm getting error about object not found when i run my code.

My code isn't too complex, but not straightforward either where the IFRAME is concerned. I have a div wrapped around the iframe as mentioned earlier because i've created a tab control effect where i have buttons across the top and depending on which "button" you click, a different page shows up inside the iframe.
I was thinking that a good place to put the fresh logic would be on the click event of the tab. but i'm getting the error that the object is not found.

So... here's some snippets from my code.

First thing i do before displaying anything is i get the data i need for the iframe from an external server. It creates a file on my local server.

GetLOData("maint")
GetLOData("hc")
%>
<HTML>
<HEAD>

<script type="text/javascript">
var tabs = new Array
(
"Tab 1 Title| "'Tab 2 Title'|);

// Align Tab: LEFT, CENTER, RIGHT
var tabAlign = "LEFT";

/*********************************************/

function tabOnClick(ID)
{
var oElement = null;

for (var i = 0; i < tabs.length; i++)
{
oElement = document.getElementById(i);
oElement.className = "tabOff";
}

oElement = document.getElementById(ID);
oElement.className = "tabOn";

var tab = tabs[ID].split("|");
divTabFrame.innerHTML = "<IFRAME SRC="+tab[1]+" ID="+tab[0]+ " CLASS='tabFrame'></IFRAME>";
document.getElementById("Tab 1 Title").contentDocument.location.reload(true);
document.body.focus();
}

function tabLoad()
{
var HTML = "";

HTML += "<P ALIGN="+tabAlign+">";
for (var i = 0; i < tabs.length; i++)
{
var tab = tabs.split("|");
HTML += "<INPUT TYPE='BUTTON' ID="+i+" CLASS='tabOff' VALUE="+tab[0]+" onClick='tabOnClick("+i+")'>&nbsp;";
}

divTabButtons.innerHTML = HTML;

for (var i = 0; i < tabs.length; i++)
{
var tab = tabs.split("|");

if (tab[2] == "*")
{
tabOnClick(i);

break;
}
}

}

</script>



And then later on, here's my code to display the iframe with divs.

<TR>
<TD colspan="3" align="left"><BR>
<DIV ID="divTabButtons"></DIV>
<DIV ID="divTabFrame"></DIV>
</TD>
</TR>

Can i have an ID with spaces in it? I guess that could be the problem.
Thanks.
 
One additional comment:
I also tried doing the reload after i do the document body focus call - see below:

document.body.focus();
document.getElementById("Tab 1 Title").contentDocument.location.reload(true);

But that didn't work.
And then I also tried reloading the DIV instead of the Iframe.
document.getElementById("divTabFrame").contentDocument.location.reload(true);

But the error message I'm getting right now is:
'document.getElementById(...).contentDocument.location' is null or not an object
 
ID's cannot have spaces in them.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Also tried contentWindow instead of contentLocation...because I'm using IE8.

document.getElementById("divTabFrame").contentWindow.location.reload(true);

still doesn't work. same error message
 
chris, i tried removing them. but that didn't resolve my problem. I also tried using the ID that gets passed in to the tabOnClick function as the iframe ID name... (a value from 0-4 because I actually have 5 tabs) but that didn't work either.

function tabOnClick(ID){ var oElement = null; for (var i = 0; i < tabs.length; i++) { oElement = document.getElementById(i); oElement.className = "tabOff"; } oElement = document.getElementById(ID); oElement.className = "tabOn"; var tab = tabs[ID].split("|"); divTabFrame.innerHTML = "<IFRAME SRC="+tab[1]+" ID=iframe"+ID+ " CLASS='tabFrame'></IFRAME>"; document.getElementById("iframe"+ID).contentDocument.location.reload(true);
document.body.focus();}

Here's a related question: When i check the html on the rendered page, i don't see the IFRAME defined anywhere... only the DIV tags. (which is why i tried reloading the DIV instaed of the IFRAMES). Is this becuase I'm creating the frames as a part of the innerHTML on the DIV?
 
(a value from 0-4 because I actually have 5 tabs)

IDs cannot start with with or be a numeric value either.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi

[tt][small][blue][ignore][sidenote][/ignore][/blue][/small][/tt]
Chris said:
IDs cannot start with with or be a numeric value either.
Sadly there is no more such restriction in HTML 5. As the OP not revealed what kind of document (s)he wrote, that may or may not be the source of problems.

( HTML5 | Elements | Global attributes | The id attribute )
[tt][small][blue][ignore][/sidenote][/ignore][/blue][/small][/tt]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top