I would like to change the meta tag in gwt and I have found the metaElement class. But how can I use it?
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");
}
}
}
Iterate over Document.get().getElementsByTagName("meta"), search for your tag by matching the attribute. Then cast the Node to MetaElement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With