Gwt change meta tag

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

+5
source share
2 answers

What we do to update the meta description 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");
        }
    }
}
+5
source

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

+2
source

All Articles