title: GWT: Calling a javascript function from Java
body: <p>Hi I am trying to call a function in a .js file from java.</p>
  
  <p>In my Java code I have</p>
  
  <pre><code>@Override
  public native void test()
  /*-{
      //JAVASCRIPT
      $wnd.h8();
  }-*/;
  </code></pre>
  
  <p>Just an Alert inside the method works but I can't call one of my functions. I've tryed $wnd, $doc and nothing.</p>
  
  <p>Say I have a functions.js with this in it:</p>
  
  <pre><code>function h8(){
      alert("hi");
  }
  </code></pre>
  
  <p>In my index I have:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
         &lt;head&gt;
  
                &lt;title&gt;GWT Test&lt;/title&gt;
                &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
                &lt;link href="styles.css" rel="stylesheet" type="text/css"&gt;
                &lt;script src="js/functions.js"&gt;&lt;/script&gt; 
  
         &lt;/head&gt;
  
         &lt;body&gt;
                &lt;div align="center" id="embed-html"&gt;&lt;/div&gt;
                &lt;script type="text/javascript" src="html/html.nocache.js"&gt;&lt;/script&gt;
         &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>So there you see I am loading the script file in the html, but I get the 'undefined is not a function' error. Whithout $doc or $wnd I get the Can't find variable h8 error.</p>
  
  <p>This is the console error:</p>
  
  <pre><code>GwtApplication: exception: (TypeError) 
   line: 112978
   column: 10
   sourceURL: http://127.0.0.1:9876/html/52574FB8FF8725CA72DFF813B62FEE86.cache.js
   __gwt$exception: &lt;skipped&gt;: undefined is not a function (evaluating '$wnd.h8()')
  (TypeError) 
   line: 112978
   column: 10
   sourceURL: http://127.0.0.1:9876/html/52574FB8FF8725CA72DFF813B62FEE86.cache.js
   __gwt$exception: &lt;skipped&gt;: undefined is not a function (evaluating '$wnd.h8()')
  </code></pre>