Class WAnchor

Direct Known Subclasses:

public class WAnchor
extends WContainerWidget
A widget that represents an HTML anchor (to link to other documents).

Use an anchor to link to another web page, document, internal application path or a resource (which specifies application-dependent content that may be generated by your application on demand). The anchor may contain a label text, an image, or any other widget (as it inherits from WContainerWidget). If you link to a document or external url, and do not want the application to terminate when the user follows the anchor, you must use setTarget(). Even for non-HTML documents, this may be important since pending Ajax requests are cancelled if documents are not served within the browser window in certain browsers.

WAnchor is an inline widget.

Note: If you set a text or image using one of the API methods like setText() or setImage() or a constructor, you should not attempt to remove all contents (using WContainerWidget.clear(), or provide a layout (using WContainerWidget#setLayout()), as this will result in undefined behaviour: the text or image are simply inserted as widgets into the container.


The widget corresponds to the HTML <a> tag and does not provide styling. It can be styled using inline or external CSS as appropriate.