How to close the Browser Window using ZK framework? - zk

I need to close the Browser Window Tab, please note not the window widget but the Browser window tab, using ZK framework version CE-9.0.0.
I have already tried the following code segments but no luck:
Clients.confirmClose(null);
Executions.deactivate(page.getDesktop());
page.setComplete(true);
page.removeComponents();
page.invalidate();
Is there any API or way to achieve this using ZK and/or JavaScript?
Is there any way to get the reference to the browser window tab, so that it can be closed programmatically, in ZK and/or JavaScript?
Please note: This window tab is opened manually & not by JavaScript or any other program.
Thanks,
RAS

Close the browser tab from a server directly is not allowed. But you can show a modal window to ask a user to close a browser tab like:
<zk xmlns:ca="client/attribute">
...
<window mode="modal" title="Close the browser tab">
<button label="Yes" ca:onClick="window.close();"/>
</window>
</zk>
Because close() is invoked by users, it will close the browser tab. This could be an alternative. Although it doesn't close a browser tab directly, the modal window covers the whole page. Users can't do anything but to click "yes", so I think most users will just click "yes" to close.
I found it works in Chrome 80, but will fail at Chrome 81. So it's not a good way

The JS to close a window is window.close(), this is a well documented standard browser API. (also answered here)
From a ZK application (server-side) you can call this script via:
Clients.evalJavaScript("window.close()");
However this browser API has strict limitations: In modern browsers you can only close windows via close() that were also opened by javascript. So you can't close the current window in case the user navigated there manually - no way around that, except for using an old browser, which I won't recommend.
e.g. that's what you'll get in Chrome (#81)

Related

Share a same popup window among different addin instances

I am making an Excel add-in by Excel JavaScript API. There is a button in this add-in, clicking on it launches popup = window.open("https://localhost:3000/#/new/", "popup", "width=1000, height=1100") and popups a browser window.
Closing the workbook or the add-in will NOT systematically close the popup. So at the moment, if I open a workbook and the add-in again, and click on the button, another browser window will popup.
I am thinking if it is possible to always use the same popup for all the excel/add-in instances. We could use localstorage to share information among different excel/add-in instances, but I am not sure if it is possible to save the popup/window there.
Does anyone have any good idea to achieve this?
For Office Add-ins, you should be using the built in Dialog API. This API ensures popups are properly handled regardless of platform (i.e. across browsers, mobile and desktop clients).
The Dialog object supports a close method, allowing you to close any open dialogs from the parent taskpane.

How can I close an UI5 App without close the tab

I want to close an UI5 app by pushing the navigation button.
Is this possible ?
Btw: How can I close the app by not closing the tab?
Thanks
Because the app is in fact a "simple" web page, the concept of closing it is somewhat loose. Some ideas that you could try, depending on what you want to achieve:
Try and close the tab, but this will generally not work, because you can only close tabs that you created yourself (see Close Current Tab).
Open the blank page by using window.open("about:blank", "_self");
Open the home page of the browser by using window.home(); (see Sending user to their browser's Home Page using Javascript)
Trigger a "Back" navigation outside of your app (such that the page that was open before your app will be shown). You can use window.go(steps) to go forward / backward in the browser history by a number of steps (negative indicates that you are going backwards). It might be tricky to get the correct number of steps that you have to go back if you have hash-based routing in your app (you could use sap.ui.core.routing.History or a similar mechanism).

How to open a popup window with an external url in a chrome app? (like window.open with _blank)

I need to open an url on a new and single tab chrome window, as you would normally do with window.open and "_blank", but when done inside a chrome app, the url is opened in a new tab of an already running chrome, ignoring all the window features options (width, height, etc).
Are we doing something wrong or is this a chrome app constrain? Any way to solve it?
Best regards
Sergio
You have two options.
Use a proper API to open a tab, chrome.browser.openTab, but that doesn't give you an ability to open it in a separate window. Such an option would probably be a nice addition, you can try submitting a feature request for it.
Open an app window with a local HTML file that embeds the required web content inside a <webview>. You then have full control over appearance, but lose access to browser's conveniences like cookie/password store of the current user, and have to implement some things yourself like dialog boxes.
I'm afraid a Chrome app cannot interact with the browser itself in a more detailed way by design.

Where should I open initial dialogs in an Eclipse application?

I have an Eclipse RCP application. When the application is started I want to immediately present the user with a login dialog. Where is the best place to do this?
I've tried to use various hooks in the WorkbenchAdvisor and WorkbenchWindowAdvisor, but all of these open a dialog before the application had a task bar icon. In this case the dialog can easily be moved behind other windows and there will be no visual indication that the application is open, and the user might open several instances of the application by mistake.
I could force the dialog to be on top, but that's not a good solution. I want a proper modal dialog. A good example of such a dialog is Firefox's "save page as" dialog. When this dialog is present it is always in front of the main browser window; you must complete or close the dialog before you can effectively resume browsing the web. However, this "save page as" dialog doesn't force itself to be on top of every window, just the browser.
You can make a splash screen your login dialog: see an example here.
First: Is it allowed to have multiple instances open? If not, you have to implement independent from the Login-Dialog-Problem something that prevents opening several instance. Take a look here (btw: I made good experiences with the server-socket thing).
Second: If you overwrite #postWindowOpen in your ApplicationWorkbenchWindowAdvisor the application is up and running (including task-item). The only drawback is that your views are already opened, you have to reload them after a successful login.

How to stop 'window.showModalDialog' opening second window?

In Microsoft's documentation I can't find the answer to my question on how to disable this feature.
The setup is that I have a browser open, that invokes the window.showModalDialog. After the user enters input in the popup window and submits a new window is opened from the pop-up.
I do not want the results from the original pop-up to open a new window. The results should be submitted back to the original browser window that invokes the first pop-up.
I've accomplished this with Mozilla and IE8, but want to make my implementation backwards compatible with other Internet Explorer versions.
This worked for me:
<base target="_self" />