I want to add a MouseOver event handler for any tag. Say, for example, that I want to add an event handler for each bind page on an outdated HTML page.
Following the GWT guide , I was able to use their JSNI method, proposed to retrieve all anchor tags after fixing small errors (missing brackets and types).
However, I want to use the elements collected in the ArrayList and bind them all to an event handler. How can i do this?
The code I wrote is below:
private native void putElementLinkIDsInList(BodyElement elt, ArrayList list) ;
private void rewriteLinksIterative() {
ArrayList links = new ArrayList();
putElementLinkIDsInList(Document.get().getBody(), links);
for (int i = 0; i < links.size(); i++) {
Element elt = DOM.getElementById((String) links.get(i));
rewriteLink(elt, "www.example.com");
}
}
private void rewriteLink(Element element, String sitename) {
String href = DOM.getElementProperty(element, "href");
if (null == href) {
return;
}
if (href.startsWith("http://")
&& !href.startsWith("http://" + sitename + "/")) {
DOM.setElementProperty(element, "href", "http://" + sitename
+ "/Blocked.html");
}
}
source
share