Nadeem Jamali
Nadeem Jamali

Reputation: 1423

Using javascript variable from GWT Java

I have defined a javascript variable in head section of html file. E.g var yourName = "Nadeem"; Now I want to utilize this variable in my gwt java file/class/method. But it shows an error: Undefined. Please suggest some hints. Best Wishes.

Upvotes: 1

Views: 1870

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

The trick is to use the right "context" where the variable is defined, i.e. $wnd:

static native String getYourName() /*-{
   return $wnd.yourName;
}-*/;

See http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#writing

Upvotes: 7

Related Questions