5

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

Gordon Lim
  • 51
  • 1
  • 2

2 Answers2

5

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");
        }
    }
}
z00bs
  • 7,518
  • 4
  • 34
  • 53
2

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

Gipsy King
  • 1,549
  • 9
  • 15