Close the browser window in Vaadin

痞子三分冷 提交于 2020-01-05 06:46:24

问题


I have google'd quite a lot but was not able to find a solution for this problem. I have a Vaadin application that runs in a browser window. I have a logout button on it, clicking on it must invalidate the session and close the browser window. I was able to get this code to invalidate the session and close the application. However, I am looking to close the browser window also, which is where I am not having any success

WebApplicationContext webCtx = (WebApplicationContext) appRef.getMainWindow().getApplication().getContext();
                HttpSession session = webCtx.getHttpSession();
                session.invalidate();
                appRef.getMainWindow().getApplication().close();

I am using vaadin 6.x and tried the following but they don't work on browsers I tried which is Chrome and IE.

            appRef.getMainWindow().executeJavaScript("window.close();");

Any ideas would be greatly appreciated. Another question I have is do I need to get the name of the main Window and then call mainWindow.close(); or just window.close() ?


回答1:


  1. Read https://vaadin.com/book/vaadin6/-/page/application.close.html if you haven't done so far.
  2. If appRef is already your Application, you do not have to call appRef.getMainWindow().getApplication() to get the Application. Just do appRef.close();
  3. Do not invalidate the session manually. It messes with the vaadin lifecycle, so the next lines are not executed anymore, at least not in the vaadin context. Just do "application.close()" and let vaadin do the rest.
  4. In vaadin 6 "window.close()" works, i use it with IE and chrome. So after you removed the session invalidation stuff, your code appRef.getMainWindow().executeJavascript("window.close()"); will work as expected.


来源:https://stackoverflow.com/questions/17839601/close-the-browser-window-in-vaadin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!