Let's say that you need to change programmatically the title of your WEB browser window.
For this you have to play with the GWT Document class, like in the below code, where we define a static function to help us:
import com.google.gwt.dom.client.Document;
...
public static void setBrowserWindowTitle (String newTitle) {
if (Document.get() != null) {
Document.get().setTitle (newTitle);
}
}
It's not rocket science, but it's very cool to know simple tricks, which help you to do what you want. Also, if you use a widgets framework like GXT (Ext GWT), SmartGWT, or GWT-Ext, be careful not to use their Document class, but the one from the GWT package, like it's shown above. Those new 'Document' classes not always behave the same :-) like the GWT.
Cheers!
Participant
Was struggling with setting the title using a native js method in smartgwt and this solved it, thanks!
ReplyDeleteI am very glad it helped -- Cheers!
ReplyDeleteWhen I get the html page using HtmlUnit-2.8 I cannot see the Title setted by Document.get().setTitle (newTitle);
ReplyDeleteAny explanation?
Cheers
Mirko
Hi Mirko,
ReplyDeletethe HtmlUnit is not supported officially by the GWT, so I cannot advice of what GWT does when si ran on this browser. How is it working on IE, FF, Chrome, Safari, Opera ?
Cheers!
Works fine on IE, FF, Chrome, Safari, Opera browser.
ReplyDeleteI use HtmlUnit just for crawler.
Many thanks
Mirko
very nice. Thank you very much. Very helpful
ReplyDelete