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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Refresh 1

Status
Not open for further replies.

dcomit

Technical User
Jun 20, 2001
115
0
0
GB
When you click refresh in a browser, it refreshes the page and returns the screen view where you last had it. Is there a way to code this action so that I can auto refresh the page and return the viewer back to where they were in the page?

Thanks,
Dave
 
Why don't you use javascript to refresh the page. Code
<html>
<head>
<title>mypage</title>
<script language=" JavaScript" ><!--
function ReloadPage()
{
window.location.reload();
}
//--></script>
</head>
<Body onLoad=" ReloadPage()" >
</html>

You can also use html meta tag to refresh the page. Code
<META HTTP-EQUIV="refresh" CONTENT="1;URL=yourpageurlhere.php">

Resource page:
 
Thank you. Not being a Java person, how would I code it to get the page to auto refresh every minute?
 
I don't know exaclty what you are doing but don't you think it will be annoying to auto refresh a page you were trying to read, even if it did then jump back to where you were?

If it's a specific part of the page that you are refreshing then you may wish to look into AJAX techniques too. This will prevent the whole page needing to be reloaded. This would make for a much, much better user experience.

Thank you. Not being a Java person, how would I code it to get the page to auto refresh every minute?

Note: It's Javascript and not Java - they are totally different things with confusingly similar names.

And by the miracle of that new thing called a search engine...
[google]javascript auto refresh[/google]



Again, I don't know what you are doing but I recently created a stock price 'widget' that needed to auto refresh.
The easiest way to do it with what was available was to make a small Flash movie that fetched and displayed the data. This was looped so it would just run constantly. No page refresh needed.


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
I can get timed auto refresh working using some code from javascriptkit.com but it always displays from the top of the page. I want it to display from the last scroll position. Is this possible?

<script>
<!--

/*
Auto Refresh Page with Time script
By JavaScript Kit (javascriptkit.com)
Over 200+ free scripts here!
*/

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="1:00"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
//-->
</script>

 
Try storing the scroll position in a cookie then performing a check for that cookie when the page loads and scroll accordingly.

Look at the document.body.scrollTop property

However, see my earlier post re:AJAX.

What is it you are building?

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Foamcow,

I'm not a Web developer so how would I store the scroll position in a cookie and retrieve it? I've asked my webby colleagues in the office and they can't help me.

The application is used for displaying real-time information from a database which is being constantly updated by another application and the page can get quite long. It's actually a list of hospital patients awaiting treatment in A&E. Some users just need a view of the top of the list whilst others need to browse further down for monitoring purposes.
 
The problem with a meta refresh, in fact any refresh is that the page won't know where to scroll to unless you somehow record that info.

You would be way better off using AJAX methods to do this.
AJAX will update just part of the screen.

You could just do a plain old META refresh as is being repeatedly pointed out but without some kind of knowledge of where to scroll to you will just jump to the top of the page each time.

If the point to scroll to is always the same then you could insert an anchor at the point you wish to scroll to.

Code:
<a name="jumpHere" id="jumpHere">
If you are working to a W3C standard Doctype you could just place an id on the element you wish to jump to.

Then your meta refresh would be

Code:
<META HTTP-EQUIV="refresh" CONTENT="1;URL=yourpageurlhere.php[COLOR=red]#jumpHere[/color]">


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Foamcow,

Cool use of Ajax. Then, however, you have no way of making the page scroll to the correct location magically. I still really like the approach, and may use it in future projects.

[plug=shameless]
[/plug]
 
I've not used Ajax in my example above.

If you used Ajax then you wouldn't need to scroll the page.
Ajax techniques let you refresh parts of the page without reloading the whole thing. Therefore it's much more seamless.

Ajax uses javascript to execute a server side script, get the resulting data and update a DOM element on the page.


The method I showed above will scroll, or rather jump to the anchor named "jumpHere".

From what I assume though, you don't want to necessarily jump to a predefined point on the page but rather to the position the user was at when the page refreshed?

In which case, I see 2 options.

1. Use Ajax as described, this application is precisely what it is for. Perhaps look at using a premade Javascript library such as Prototype.

2. Use javascript to grab the scroll position of the page. Then store that in a cookie and reload the page. When the page loads perform a check for the presence of said cookie and if it exists use Javscript to scroll the page to that position.


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
I was thinking that you meant to use Ajax to do the inserting of the anchor or id, but I suppose that doesn't need the http request back to the server for anything.

I suppose that with Ajax you'd just insert the updated content into the middle of the page... Like Googles applcations (esp. gmail) does.

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top