简体   繁体   English

使用GWT Java中的javascript变量

[英]Using javascript variable from GWT Java

I have defined a javascript variable in head section of html file. 我在html文件的头部定义了一个javascript变量。 Eg var yourName = "Nadeem"; 例如var yourName =“ Nadeem”; Now I want to utilize this variable in my gwt java file/class/method. 现在,我想在我的gwt java文件/ class / method中利用此变量。 But it shows an error: Undefined. 但是它显示了一个错误:未定义。 Please suggest some hints. 请提出一些提示。 Best Wishes. 最好的祝愿。

The trick is to use the right "context" where the variable is defined, ie $wnd : 诀窍是在定义变量的地方使用正确的“上下文”,即$wnd

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM