To intercept clicks on your anchor inside your html you can listen for click events for the contentHtmlPanel and check if an anchor has been clicked. Here is a short example using HTMLPanel:
public void onModuleLoad() { HTMLPanel contentHtmlPanel = new HTMLPanel("Hello <a href=\"#world \">World</a>"); contentHtmlPanel.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Element e = DOM.eventGetTarget(Event.as(event.getNativeEvent())); if(e instanceof AnchorElement) { AnchorElement anchor = (AnchorElement) e; String href = anchor.getHref(); //absolute URI String hrefAttribute = anchor.getAttribute("href"); //href attribute value Window.alert("href:\n\n" + href + "\n\nhrefAttribute:\n\n" + hrefAttribute); } } }, ClickEvent.getType()); RootPanel.get().add(contentHtmlPanel); } If your HTMLPane is a custom widget you can also do the following: 1.) Create a custom GwtEvent and its corresponding Handler, e.g.: public class AnchorClickedEvent extends GwtEvent<AnchorClickedEventHandler> { .. getter method for your needed information .. } public interface AnchorClickedEventHandler extends EventHandler { public void onAnchorClicked(AnchorClickedEvent event); } 2.) Give your HTMLPane a new method (maybe through a HasAnchorClickEventHandlers interface): public HandlerRegistration addAnchorClickedEventHandler(AnchorClickedEventHandler handler) { return this.addHandler(handler, AnchorClickedEvent.TYPE); } 3.) Add this.sinkEvents(Event.ONCLICK) to your HTMLPane's constructor and then overwrite onBrowserEvent(Event event). In the onBrowserEvent method you check for click events and do the same as in onClick() from the code above. The line "Window.alert(...)" will become this.fireEvent(new AnchorClickedEvent(<your needed information, e.g. href attribute value>)) That way you should be able to attach AnchorClickedEventHandlers to your custom HTMLPane and your Event will have the information you need. You could also use the EventBus if you like. Just skip step 2 and fire your event through the eventbus in step 3. On 2 Dez., 10:15, wawuvu <rentsch.dan...@gmail.com> wrote: > Hello everyone, > > I've been searching quit a lot for a solution to this problem but all > I found wasn't 100% satisfactorily: > > I use RPCs in my GWT project to get some texts like > > String text = " ...bla bla <a href='#ID123'>open me</a> > blablalb ...."; > > Those strings will be loaded into the content of a HTMLPane like this: > > contentHTMLPane = new HTMLPane(); > contentHTMLPane.setContents(text); > > And the user can see the new content after the RPC. What I need is the > following: > > When the user clicks on <a href='#ID123'>open me</a> it should call > the method: > > public void openConent(String id){ > ... > > } > > ...of course with the ID of the Link. The openContent method is > present in the class which processes the text and so on. > > So I have to observe the "user clicks on a hyperlink" event somehow. > Somehow like: > > (pseudocode) > > if(eventHyperlinkOccurs) { > > this.openConent(event.getURLofLink); > > } > > All I've found is > this:http://googlewebtoolkit.blogspot.com/2008/07/getting-to-really-know-g... > which tells me that it's possible to call JAVA methods with JS > methods. This solution is OK but I've been wondering if there is a > "smaller" solution with events/observers? > > Thanks in advance! -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.