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.
Here is how you do it on Chrome and IE:--<script type = "text/javascript">
function closeWindow(){window.open('','_self','');</script>
window.close();
}There is more discussion here: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.com wrote:Hi,I use JSNI codepublic 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+unsubscribe@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.
No comments:
Post a Comment