Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Javascript variable in GWT

I have a variable in Javascript, which toggles between true and false when full-screen mode is switched on and off, respectively. Now I want to access that variable in my GWT code, and do some actions accordingly. Can anyone tell me how to do it? I couldn't understand it from the Google documentation on JSNI...

like image 606
SexyBeast Avatar asked Dec 09 '22 18:12

SexyBeast


1 Answers

In JavaScript

var mybool = true;

your JSNI method in MyClass class ;

public static native boolean getNativeVariableType(String jsVar)/*-{
        return  eval('$wnd.' + jsVar);
    }-*/;

Finally using in GWT ;

boolean getFormJs = Myclass.getNativeVariableType("mybool");

As @dodoot raised the point you can try this return !!$wnd[jsVar] to get ridoff eval function side effects.

As @manolo said if you are using gwtQuery it will be more handy by writing simply $(window).prop("mybool").

like image 187
Suresh Atta Avatar answered Dec 11 '22 07:12

Suresh Atta