Anchors / Links within a page

7 views
Skip to first unread message

obesga

unread,
Dec 19, 2008, 10:54:17 AM12/19/08
to Google Web Toolkit
Hello everyone !
Just a problem with anchors and IE

I've been trying to make a looong GWT page 'navigatable' withih with
the classic HTML anchor tag ( something like an index; you'll see it
pretty here http://www.echoecho.com/htmllinks08.htm )

Using Peter Blazejewicz code on the forums (
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/61e10f6f83b22baa/87edf101312b59ab?lnk=gst&q=anchor+within+page#87edf101312b59ab
) I've managed to make this happen... Except in IE, where links simply
don't work - either in GWTShell or IE stanalone
(I've tried in Opera / Firefox / Chrome / Safari, all these works
fine )

¿ Is there any problem or workaround to IE ?

or

¿ Can it be done programatically, with GWT Java code or Javascript
code ( by JSNI ) ?

The code is like that

// Link
Element element = DOM.createAnchor();
setElement(element);
DOM.setElementAttribute(element, "href", anchorName ==
null ? "" : "#" + anchorName);
DOM.setInnerText(element, text == null ? "" : text);

// Target
Element element = DOM.createAnchor();
setElement(element);
DOM.setElementAttribute(element, "name", anchorName ==
null ? "" : anchorName);
DOM.setInnerText(element, text == null ? "" : text);

Thank you

Oskar

obesga

unread,
Dec 19, 2008, 10:59:05 AM12/19/08
to Google Web Toolkit
///**** I don't like to re-post, but here's the complete code of what
I'm trying to to *****///

public class AnchorsPanel extends Composite {

private FlowPanel fpLinks;
private VerticalPanel verticalPanel;

public AnchorsPanel() {
verticalPanel = new VerticalPanel();
verticalPanel.setStylePrimaryName("caronte-VerticalTabPanel-
VPanel");
fpLinks = new FlowPanel();
verticalPanel.add(fpLink);
this.initWidget(verticalPanel);
}

// ADD A WIDGET
public void addTab(String name, String refName, Widget widget) {
HTMLLinkSource sourceLink = new HTMLLinkSource(name,refName);
HTMLLinkTarget targetLink = new HTMLLinkTarget(name,refName);
fpLinks.add(sourceLink);
verticalPanel.add(targetLink);
verticalPanel.add(widget);
}



// CLASS FOR LINK
public class HTMLLinkSource extends Widget {

public HTMLLinkSource(String text, String anchorName) {
Element element = DOM.createAnchor();
setElement(element);
DOM.setElementAttribute(element, "href", anchorName ==
null ? "" : "#" + anchorName);
DOM.setInnerText(element, text == null ? "" : text);
}

}

// CLASS FOR TARGET
public class HTMLLinkTarget extends Widget {

public HTMLLinkkDestino(String text, String anchorName) {

todd....@gmail.com

unread,
Dec 19, 2008, 11:50:43 AM12/19/08
to Google Web Toolkit
Element element = DOM.createElement("<a NAME=\""+(anchorName == null ?
"" : anchorName)+"\"></a>");

You would have to create the anchor like this in IE but it does not
work for Firefox.

obesga

unread,
Dec 22, 2008, 9:23:21 AM12/22/08
to Google Web Toolkit
Well, thank you !! Now it works..... nut not at all. Here's the new
code


/***********CODE BEGIN
****************************************************************/
public class HTMLLinkkDestino extends Widget {

private static native boolean detectIE()/*-{
return /MSIE (\d+\.\d+);/.test(navigator.userAgent)
}-*/;

private static boolean isIE = detectIE();


public HTMLLinkkDestino(String text, String anchorName) {
Element element;
if (isIE) {
element = DOM.createElement("<a NAME=\"" + (anchorName
== null ? "" : anchorName) + "\"></a>"); //" + (text == null ? "" :
text) + "
} else {
element = DOM.createAnchor();
DOM.setElementAttribute(element, "name", anchorName ==
null ? "" : anchorName);
}
DOM.setInnerHTML(element, text == null ? "" : text);
setElement(element);
}

/***********CODE END
****************************************************************/



The fact is the anchors work, but in IE ( I hate this browser ;) ),
when the user press the source link, the page scrolls to the point;
and a second later it rechages itselft.... losing the state of the
application. Only in IE.
I'm looking about preveting the event, but I'm not sure how to make it
work... ufff

Oskar


On 19 dic, 17:50, "todd.sei...@gmail.com" <todd.sei...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages