How to create a GWT anchor with an ignored href?
Let's say I have HTML anchor like so:
<a id="myid" href="something?a=b">Link</a>
and I want to wrap this in a GWT Anchor that has a click handler that sends the user somewhere else and ignores the href value.
in regular javascript it seems like you can accomplish this by doing:
<a id="myid" href="som开发者_如何学运维ething?a=b" onclick="goSomewhereElse(); return false;">Link</a>
But in GWT there doesn't appear to be a way to do it ... am i missing something?
Thanks!
Can you just use the g:Anchor tag instead of a?
<g:Anchor ui:field="myLink1">The Link To Click</g:Anchor>
And then in your implementation of the file you could have something like...
@UiField
protected Anchor myLink1;
@UiHandler("myLink1")
public void handleMyLink1Click(ClickEvent event)
{
//code to execute on click;
event.preventDefault(); //If you want the href present
}
This would eliminate the need to have the href present at all. Also, if you need to have the href present, since you have the clickEvent you could add event.preventDefault() to the UiHandler. (as seen on the second line in the UiHandler)
Maybe I completely missed what you were going for, but I hope this helps a little! :)
Use Anchor
and add a ClickHandler
to it.
Create an Anchor
as new Anchor(textToDisplay)
and add a ClickHandler
to it.
Change it to:
<a id="myid" href="javascript:;">Link</a>
精彩评论