本文介绍了关闭Vaadin中的浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google上工作了很多,但是找不到解决此问题的方法。我有一个在浏览器窗口中运行的Vaadin应用程序。我上面有一个注销按钮,单击它必须使会话无效并关闭浏览器窗口。我能够获得此代码来使会话无效并关闭应用程序。但是,我也想关闭浏览器窗口,这是我没有成功的地方

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();

我正在使用vaadin 6.x,并尝试了以下操作,但它们在我尝试使用的浏览器上不起作用

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();");

任何想法都将不胜感激。我的另一个问题是我需要获取主窗口的名称,然后调用mainWindow.close();吗?还是只是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. 阅读如果

  2. 如果appRef已经是您的应用程序,则不必调用 appRef.getMainWindow()。getApplication()获取应用程序。只需执行 appRef.close();

  3. 不要手动使会话无效。它与vaadin生命周期混乱,因此不再执行下一行,至少不在vaadin上下文中执行。只需执行 application.close(),然后让vaadin完成其余工作。

  4. 在vaadin 6中, window.close()有效,我将其与IE和chrome一起使用。因此,在删除会话无效内容之后,您的代码 appRef.getMainWindow()。executeJavascript( window.close()); 将按预期工作。

  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.

这篇关于关闭Vaadin中的浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:03