Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT clickable link (anchor) without href

Tags:

gwt

I'm trying to create a link (anchor) in GWT that can be clicked and it's ClickEvent can be processed, while at the same time this anchor wouldn't reload the page. This basically means that a href must not be set.

In javascript this is done like this:

<a href="javascript:handleAnchorClick();">Link</a> 

or with

<a href="#" onclick="return handleAnchorClick()">Link</a>  

where handleAnchorClick() returns false.

What would be the best way to achieve this in GWT?

like image 967
Peter Knego Avatar asked Dec 04 '10 23:12

Peter Knego


People also ask

Can anchor tag have no href?

Yes, it is valid to use the anchor tag without a href attribute. If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.

Is href mandatory for a tag?

The tag is fine to use without an href attribute. Contrary to many of the answers here, there are actually standard reasons for creating an anchor when there is no href. Semantically, "a" means an anchor or a link. If you use it for anything following that meaning, then you are fine.

How do you make an anchor tag refer to nothing?

To make an anchor tag refer to nothing, use “javascript: void(0)”. The following link does nothing because the expression "0" has no effect in JavaScript. Here the expression "0" is evaluated, but it is not loaded back into the current document.

What is href in anchor tag?

(Hypertext REFerence) The HTML code used to create a link to another page. The HREF is an attribute of the anchor tag, which is also used to identify sections within a document.


1 Answers

Use tha Anchor element, and call its addClickListener() method and add in what ever logic you wish. This sort of anchor doesn't reload the page.

like image 63
Chii Avatar answered Oct 31 '22 08:10

Chii