Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gwt change meta tag

Tags:

gwt

I would like to change the meta tag in gwt and I have found the metaElement class. But how can I use it?

like image 552
Gordon Lim Avatar asked Nov 23 '10 08:11

Gordon Lim


2 Answers

That's how we do it for updating the description meta tag:

public void onModuleLoad() {
    Button btn = new Button("update description");
    btn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            updateDescription();
        }
    });

    RootPanel.get().add(btn);
}

private void updateDescription() {
    NodeList<Element> tags = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < tags.getLength(); i++) {
        MetaElement metaTag = ((MetaElement) tags.getItem(i));
        if (metaTag.getName().equals("description")) {
            metaTag.setContent("new description");
        }
    }
}
like image 117
z00bs Avatar answered Sep 28 '22 19:09

z00bs


Iterate over Document.get().getElementsByTagName("meta"), search for your tag by matching the attribute. Then cast the Node to MetaElement.

like image 44
Gipsy King Avatar answered Sep 28 '22 17:09

Gipsy King