1

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.

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

It was so hard to find this solution. I'm glad it was easier than I was imagining in my head. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.