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 gkittelson 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 web page EXACTLY twice automatically?

Status
Not open for further replies.

Lyndsey2004

Programmer
Jun 4, 2004
5
US
Title pretty much describes it. I have a web page that is loading some dynamic content. I have figured out that it needs to be refreshed exactly twice before the content will appear correctly. I know how to get a page to refresh automatically every x seconds, but I need it to refresh EXACTLY TWICE. Any suggestions?
 
Dynamic content shouldn't behave this way and suggests an underlying problem. Can you post a link to this page?

There's always a better way. The fun is trying to find it!
 
Toggle between these two pages:


You will see that the first one has a Flash movie that reads the page title (on page 141, it's "*** New Page ***"). This is coming from a dynamically generated textfile in an iframe that is 1x1 pixels right below the "Content Goes Here". See the tiny dot?

Now, go to the second page. Page 143. Upon loading this page, the title should read "Abracadabra h", but it doesn't until you refresh it twice. Once you get the right title to come up on 143, go back to 141. Now you will have to refresh it twice also.

The first refresh takes care of page.asp's command to generate the proper "Name=blahblahblah" statement to the txt file in the iframe. The second refresh takes care of updating the Flash movie... flash movies are notoriously hard to update. They like to be cached!

So, you can see, what I'm trying to do here is have myself a little dynamic text generator so my clients can type in any old page title in their admin tool and it will come out in perfect green and white 30 pt Century Gothic.
 
I get "Abracadabra h" in green and white on the initial page load! I'm using Mozilla on Windows XP Pro and a DSL connection.

Some observations...
Remove the extra <html></html> tags - you only use one set per web page. Same for <body></body> & <head></head> tags. Also, ALL meta tags go between the <head></head> tags.

You've got a lot of <table> tags with no matching </table> tags.

Put all of your CSS styles in a single style sheet instead of scattering them all over the page. This can confuse some browsers.

Same for your javascript functions. Put as many of your javascript functions into a single set of <script></script> tags. Better yet, put them in an external file - it's cleaner and easier to work with. Same for your CSS style sheets - put all your style definitions in a single external file.

Lose the <span> tags that surround your <html> tags - they don't belong there. <span> tags, when needed, go between the <body> tags.





There's always a better way. The fun is trying to find it!
 
Really?! Hmmmm... well, I knew the code was very messy (happens when you're on a deadline), but I didn't think about it bogging the whole thing down. I will try to clean it up and let you know what I find.
 
Over the weekend I cleaned up the code considerably... but to no avail. You will now notice that the javascript and the CSS are now in external files. Sometimes the links to those external files (.css and .js) are repeated because of the format of the page: it is actually three pages butted up against each other. The header, the content, and the footer.

Anyway, on my PC, no matter how much I cleaned it up it still was not refreshing the flash file. My PC is running XP with IE6. I tried it on my laptop running 2000 with IE6 and it worked great.

On my PC, I went into

Tools > Internet Option > General Tab > Temporary Internet Files Settings

Then I checked the radio button that says "Check for newer versions of stored pages EVERY VISIT TO THE PAGE". I had it on "AUTOMATICALLY". Voila! It works now.

So that narrows it down to a Cacheing issue. I've tried just about everything from this page:


You can tell because there are no-cache statements floating all over the page. Better to be safe than sorry, right? Well, it still doesn't work. I'm pulling my hair out at this point. Most people will have their cache on, and I figured this was the only way to not cache the page. Am I missing something?

(should say ABC DEF)
(should say ABRACADABRA H)
 
You need some more code cleaning, having several sets of <head></head><body></body> tags is very likely to be causing all kinds of issues with the strict browsers. IE being not very strict about these thing will have little or no problem with it. Moz, NS etc may well have problems.

Your <head></head>, meta tags and opening <html><body> tags should only be in the header include page and the closing </body></html> should be in the footer include. that way there is only one instance of each tag in the completed page.



Chris.

Indifference will be the downfall of mankind, but who cares?
 
Your page should have only one set of the following tags:

<html></html>
<head></head>
<title></title>
<body></body>

Also, you should only have one reference to your external CSS and JS files.

Like Chris says, more than this will likely confuse just about any browser.

There's always a better way. The fun is trying to find it!
 
While I agree with everyone that you have some kind of underlying problem that causes you to "need" to refresh exactly twice, I will attempt to answer the question you asked.

What I would do, if (for whatever reason) I needed to refresh a page twice, would be to check the url for the parameter 'refresh'. If I did not find it, I would reload the page, adding refresh=1 to the URL.

If I DID find the parameter, I would check the value, if it is 1, then I reload, changing the parameter to refresh=2. If it was 2, I would leave it alone (i.e., NOT reload the page).

example:
Code:
var refreshFound = false;
var paramList = document.location.search;
if(paramList.length > 0)
 paramList = paramList.substring(1); //removes '?'
var paramPairs = paramList.split("&");
for(var i=0; i<paramPairs.length; i++)
{
 var paramNameAndValue = paramPairs[i].split("=");
 if(paramNameAndValue[0] == "refresh")
 {
  refreshFound = true;
  if(paramNameAndValue[1] == 1)
  {
   var newLoc = document.location.href.substring(0, document.location.href.indexOf("?"));
   for(var j=0; j<paramPairs.length; j++)
   {
    if(j>0)
     newLoc += "&";
    else
     newLoc += "?";
    if(j == i)
     newLoc += "refresh=2";
    else
     newLoc += paramPairs[j];
   }//end for
   this.location = newLoc;
  }//end if
 }//end if
}//end for

if(!refreshFound)
{
 if(document.location.href.indexOf("?") > -1)
  this.location = document.location.href + "&refresh=1";
 else
  this.location = document.location.href + "?refresh=1";
}

I got this working for me in IE6.

'hope that helps. Keep looking for those other underlying problems. Right now, they are manifesting themselves as a need for this little double-refresh trick. They might continue to force you to seek other shortcuts and tricks to the point where things get totally out of control and (perhaps) your page becomes unusable.

Good luck.

--Dave
 
LookingForInfo's solution is somewhat correct. It does achieve the desired result, but for some reason (whether I placed it at the top or bottom or both) it didn't help to refresh my page the way I needed it to. i.e. it refreshed everything except the flash file... weird.

I expanded the iframes to 100 pixels so you can see what's going on in depth.

I cleaned the code EVEN more to ensure that there is only one set of <body> tags. Then I ensured that there were either one or two sets of the <head> tags: some articles instruct you to place the <head> tag at the bottom as well as the top to enfore the no-cache rule.

I tried every possible combination I could think of. Meta tags with "expires", "Pragma", and/or "Cache-control". I tried rearranging them, using the head tags at the top only, bottom only, and both. I can tell that my pages are still being loaded from my cache because they load quickly and the flash file is still wrong.

I even read articles about how to specifically not cache the SWF file. Tried and failed there also.

I am providing the ASP code that drives the three page parts; perhaps the problem is in the ASP instead of the HTML. One wouldn't think so, but I'm getting desperate. I already tried ASP commands to assist in not cacheing. If you all think I should relist this issue in the ASP board, I will do so and close this post up.

--------------------------------------------------------
pagetop.asp
--------------------------------------------------------
Code:
<head>	
    <title>YIL of Kansas City ::  816.235.6789</title>
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">	
</head>
<body>
<SCRIPT language=javascript src="js_include1.js"></SCRIPT>
<!-- #INCLUDE VIRTUAL="/common/dbconn.asp" -->
<div align="center">
  <table width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td>
          <!-- #INCLUDE VIRTUAL="pagetop_include.asp"-->	  	  	 
			<%=message%>
			<p><%=pagedata%></p>
       </td>
    </tr>
  </table>
</div>

--------------------------------------------------------
pagebottom.asp
--------------------------------------------------------
Code:
<!-- #INCLUDE VIRTUAL="/common/dbconn.asp" -->
<div align="center">
  <table width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td>
			<!-- #INCLUDE VIRTUAL="pagebot_include.asp" -->	  
			<%=message%>
			<p><%=pagedata%></p>
	  </td>
    </tr>
  </table>
</div>dbconn
</body>

--------------------------------------------------------
page.asp
--------------------------------------------------------
Code:
<!-- #INCLUDE VIRTUAL="/common/dbconn.asp" -->
<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO, objTextFile

' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
Set objTextFile = objFSO.CreateTextFile(Server.MapPath("textfile.txt"))

ID = Trim(request.querystring("id"))
	ID = request("ID")
	if not isNumeric(id) or id = "" then
		response.redirect("default.asp?not_number")
	end if

if not IsNumeric(ID) then
	whtConn.Close
	Set whtConn = Nothing
	response.redirect("/")
end if

'---------------------------------------------------------


'*****IF POSTBACK THEN UPDATE********


Set dataRS = Server.CreateObject("ADODB.RecordSet")
ID = request("ID")
whtSQL = "Select ID, pagedata, pagename, active, directlink FROM tblPages where ID = " & ID & ";"
'Response.Write whtSQL
dataRS.Open whtSQL, whtConn, 1
		recordcount = dataRS.recordcount
		if recordcount <> 1 then
			dataRS.Close
			Set dataRS = Nothing
			whtConn.Close
			Set whtConn = Nothing
			response.redirect("default.asp?norecord")
		end if
pagename = dataRS("pagename")
objTextFile.WriteLine "Name=" & pagename
ID = dataRS("ID")
pagedata = dataRS("pagedata")
directlink = dataRS("directlink")

active = dataRS("active")


'close connections,etc..
dataRS.Close
Set dataRS = Nothing
whtConn.Close
Set whtConn = Nothing

' Close the file.
objTextFile.Close

' Release reference to the text file.
Set objTextFile = Nothing

' Release reference to the File System Object.
Set objFSO = Nothing


'---------------------------------------------------------
%>
<!-- #INCLUDE VIRTUAL="/common/dbconn.asp" -->
<!-- #INCLUDE VIRTUAL="/common/databasepage.asp" -->

<%
	if active = 1 then
		server.Execute("pagetop.asp")
	else	
	end if
%>
<%=announce%>
<%
	if active = 1 then
		server.Execute("pagebottom.asp")
	else	
	end if
%>

--------------------------------------------------------
END
--------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top