Hi -b,
If you want a page to be scrolled to the same scroll position as when
a form within that page is submitted, I may be able to help as that is
something I did recently. This is a crude solution using html and
javascript, but worked well enough for me.
In the page head section, include these javascript functions:
// Record the document scroll position in our hidden field that has id
'hidScroll'
function recordScroll(thisPage)
{
//alert("pos: " + document.body.scrollTop);
var hidScroll = document.getElementById('hidScroll');
hidScroll.value = document.body.scrollTop;
}
// Get the value from the hidden field identified by id
'hidScrollReturn' which is
// passed back the previous scroll position from the server with each
refresh
function goToScroll()
{
var hidScrollReturn = document.getElementById('hidScrollReturn');
//alert("hidScrollReturn value: " + hidScrollReturn.value);
document.body.scrollTop = hidScrollReturn.value;
}
</script>
Then include this in the <body... to force the page to go to the
returned scroll position when it has loaded and also to record the
latest scroll position after each scroll event.
<!-- Note that onscroll seems to run before onload triggers, which is
why there has to be
a separate hidden field for returning the value (if the same
field is used, the onscroll
clears it back to zero before the onload has time to
goToScroll) -->
<body onload="goToScroll();" onscroll="recordScroll(this)">
Include two hidden fields in the form that is being submitted, defined
in the wod like this:
hiddenScrollPosField: WOTextField {
id = "hidScroll";
type = "hidden";
value = scrollPosition;
}
hiddenScrollPosReturnField: WOTextField {
id = "hidScrollReturn";
type = "hidden";
value = scrollReturnPosition;
}
The component java class then has variables that accept the latest
scroll position when the form is submitted and one to pass the scroll
position back when the page is returned.
John
On 25 Mar 2008, at 16:32, Anthony B Arthur wrote:
I have code that will scroll to an anchor after a page refresh, but
it always goes to the top. How can I make it refresh with the
anchor in the middle, or better yet, refresh with the anchor exactly
where it was when the user invoked a submit? The code I have is:
public void appendToResponse(WOResponse response, WOContext
context) {
if (pageAnchor != null && advanceToAnchor) {
response.setHeader(context.componentActionURL() + "#" +
pageAnchor, "location");
response.setHeader("text/html", "content-type");
response.setHeader("0", "content-length");
response.setStatus(302);
pageAnchor = null;
advanceToAnchor = false;
}else{
super.appendToResponse(response, context);
}
}
Any ideas?
-b
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]