This answer has what you are looking for:
http://stackoverflow.com/questions/8617055/how-to-run-javascript-function-from-gwt-java-with-jsni


Specifically in Java:

myButton.addClickHandler(new ClickHandler(){
        public void onClick(ClickEvent event) {
            closeWindow();
        };
    });

public static native void closeWindow() /*-{  $wnd.closeWindow();}-*/;

Then in JavaScript in your app's .html page:

<script type="text/javascript" language="javascript">
    function closeWindow() {
        window.open('','_self',''); 
                window.close(); 
    }</script>

Someone please correct me if this isn't the proper way to call JavaScript 
from Java within GWT. I haven't tested this, but from the documentation and 
a lot of various questions/answers, this appears to be the way to do it. 
Especially when not using UIBinder and doing everything through GWT 
Designer and/or normal Java editors as Nalini needs.



On Tuesday, March 12, 2013 11:40:15 PM UTC-4, Michael Prentice wrote:
>
> Here is how you do it on Chrome and IE:
> http://productforums.google.com/forum/#!topic/chrome/GjsCrvPYGlA
> http://productforums.google.com/forum/#!topic/chrome/k7aKtZlalqU
>
> <script type = "text/javascript"> 
>
>    function closeWindow(){ 
>         window.open('','_self',''); 
>         window.close(); 
>    } 
>
> </script> 
>
> There is more discussion here:
>
> http://stackoverflow.com/questions/8301780/javascript-code-to-close-tab-that-works-in-ie-firefox-and-chrome
>
> It explains that JavaScript can only close windows that were opened by 
> JavaScript.
>
>
> On Tuesday, March 12, 2013 5:44:03 PM UTC-4, nalin...@googlemail.comwrote:
>>
>> Hi,
>>  
>> I use JSNI code
>>  
>> public static native void closeBrowser()
>>     /*-{
>>         $wnd.close();
>>     }-*/;
>>  
>> to close my GWT app. It doesnt work with browsers other than IE....
>>  
>> Any suggestions?
>>  
>> Regards,
>> Nalini.K
>>  
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to