0

i have a page with lots of hrefs link to arbitrary points of the page, say when i click the link <a href="#b">B</a> i should go to the point B. however i don't wanna update the history stack when i click the link, which by default will be udpate to /index.html#B. i can use g:Anchor instead of hyperlink to avoid updating history stack, but how can i really go to the point B in my page? my code looks like this: index.ui.xml

      <g:Anchor ui:field="_a">A</g:Anchor>
      ...
      <a name="a"></a>
        <h3>Point A</h3>
      <a name="b"></a>
        <h3>Point B</h3>
      ...

index.java

@UiField
Anchor _a;
@UiHandler("_a") 
void onClickA(ClickEvent e){
    //how to goto point A in the page ??
}
user468587
  • 4,799
  • 24
  • 67
  • 124

3 Answers3

0

Maybe you can use Window.scrollTo() method ?

  • i tried but it didn't work(didn't scroll at all): onClickA(ClickEvent e) {Element aElem = container.getElementById("a"); if (aElem != null) { Window.scrollTo(aElem.getAbsoluteLeft(), aElem.getAbsoluteTop();}} – user468587 Mar 13 '12 at 22:31
0

What you possible can do is call: _a.getElement().scrollIntoView();. This scroll to the anchor such that it is at least visible.

Hilbrand Bouwkamp
  • 13,509
  • 1
  • 45
  • 52
0

I hope this is already Discussed,

gwt anchor tag not anchoring

GWT clickable link (anchor) without href

Community
  • 1
  • 1
Vijay Sarin
  • 1,326
  • 1
  • 11
  • 31