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!

Page refresh back to it's last position

Status
Not open for further replies.

SonicBoomBand

Technical User
Jun 4, 2004
42
0
0
GB
Hi all

I have a webpage that allows a user to update via input boxes. All is well and works like a treat but they have requested that the page, after refresh, keeps it's position.

For example, the page is quite long and there are input boxes at the bottom of the page. When the user enters a value the page refreshes back to the top.

Is there a html tag that allows me to force the page back to the area where the input boxes are?

Andrew Chamberlain
National Grid
 
Hi

No, there is no such HTML tag. There is a question instead. What does that button when you press it ?

This will keep the position in Mozillas and Opera but not in Safari and Explorer ( at least not up to 6 ).
Code:
<input type="button" value="Refresh" onclick="location.reload()">
Or do it with JavaScript. This works in Mozillas, Opera and Explorer. And I think I have a configuration problem in my Safari...
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript">
function savepos()
{
  var pos=0
  if (window.innerHeight) pos=window.pageYOffset
  else if (document.documentElement && document.documentElement.scrollTop) pos=document.documentElement.scrollTop
  else if (document.body) pos=document.body.scrollTop
  document.cookie='scrollpos='+pos
}
function restorepos()
{
alert(document.cookie)
  var part=document.cookie.split(/; +/)
  for (var i=0;i<part.length;i++)
    if (part[i].indexOf('scrollpos=')==0)
      scrollTo(0,part[i].substring(10))
}
window.onload=restorepos
</script>
</head>
<body>
<p>
bla-bla
</p>
<form action="#">
<p>
<input type="button" value="Refresh" onclick="savepos();location.reload()">
</p>
</form>
</body>
</html>

Feherke.
 
You could submit the form to a location with a bookmark, for example:

Code:
<form action="whatever.jsp#wibble" ...>

and then have a bookmark called "wibble" at the top of the section with that form in.

I've not tried it, but it might work.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I've now had confirmation from my colleague that something like that should work.

If I add, for example
<a name=wibble></a>
into my HTML and then at the end of my url that refreshes that page, have '#wibble', the page should goto that position.

Feherke, in answer to your question, the button runs the webclass that inserts the data in the input boxes into a Sql database and then refreshes the page to show the new figures and calculated values.

Andrew Chamberlain
National Grid
 
I have had the same problem in the past. I ended up using a tags ( <a name="one"></a> ). I can't remember why, but when my script ran, the output was a blank HTML page with a meta refresh tag in the head which refreshed to the homepage (a=one) in 1 second. The hyperlink I used was
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top