GWT: Calling a javascript function from Java -
hi trying call function in .js file java.
in java code have
@override public native void test() /*-{     //javascript     $wnd.h8(); }-*/;   just alert inside method works can't call 1 of functions. i've tryed $wnd, $doc , nothing.
say have functions.js in it:
function h8(){     alert("hi"); }   in index have:
<!doctype html> <html>        <head>                <title>gwt test</title>               <meta http-equiv="content-type" content="text/html; charset=utf-8">               <link href="styles.css" rel="stylesheet" type="text/css">               <script src="js/functions.js"></script>          </head>         <body>               <div align="center" id="embed-html"></div>               <script type="text/javascript" src="html/html.nocache.js"></script>        </body>  </html>   so there see loading script file in html, 'undefined not function' error. whithout $doc or $wnd can't find variable h8 error.
this console error:
gwtapplication: exception: (typeerror)   line: 112978  column: 10  sourceurl: http://127.0.0.1:9876/html/52574fb8ff8725ca72dff813b62fee86.cache.js  __gwt$exception: <skipped>: undefined not function (evaluating '$wnd.h8()') (typeerror)   line: 112978  column: 10  sourceurl: http://127.0.0.1:9876/html/52574fb8ff8725ca72dff813b62fee86.cache.js  __gwt$exception: <skipped>: undefined not function (evaluating '$wnd.h8()')      
you should define window function:
window.h8 = function() {     alert("!!!"); };   and access $wnd.
private static native void callfunction() /*-{     $wnd.h8(); }-*/;      
Comments
Post a Comment