• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: scroll to anchor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scroll to anchor


  • Subject: Re: scroll to anchor
  • From: John Pollard <email@hidden>
  • Date: Tue, 25 Mar 2008 21:28:50 +0000

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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >scroll to anchor (From: Anthony B Arthur <email@hidden>)

  • Prev by Date: Re: Click to Open :-)
  • Next by Date: Re: Click to Open :-)
  • Previous by thread: scroll to anchor
  • Next by thread: Click to Open :-)
  • Index(es):
    • Date
    • Thread