On Jan 8, 7:27 pm, Thad <[email protected]> wrote:
> Tom, is there any way to capture the value of an anchor's href in my
> GWT code?
>
> My situation is that my application receives String from an RPC call
> that is bounded by the <pre> tag and contains any number of anchors.
> I display this in a HTML object in a SimplePanel in a ScollPanel for
> the user to read. Clicking on one of the anchors is supposed to
> request some additional info from the server about the text
> highlighted by that anchor. (The text file itself is from a text
> search database. The anchors mark items in the document that cause
> the document to be a search hit.)
>
> The href's I've been creating on the server point back into my
> application with a history token that makes the server call and pops
> up a dialog box. This works fine in Firefox and Safari, but on IE I
> have jd's problem--my application reloads.
>
> Calling preventDefault() inside the click handler for my HTML object
> stops the call, but I need the data in the href to do anything useful
> (like make my next server call and show a pop-up at NativeEvent client
> x and y).
Ah, OK, so in your case, retrieving the NativeEvent's EventTarget, cast
()ing into an AnchorElement (well, first verifying that it *is* an "A"
element by checking its getTagName(), and walking the tree up until
the HTML widget's getElement() or an "A" element is found) then
calling AnchorElement#getHref() should give you what you want. Then
get the indexOf("#") and then the substring(hashIndex) to pass it to
History.newItem(...).
You'll find similar code walking up a DOM tree in
HTMLTable#getEventCellTarget (or a similar named private/protected
method, this is from memory), in this case it's looking for "TD"
elements.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.