0

On the app i'm currently developping, I have several hyperlink to standard sap backend transaction such as BP, PDL and so on. i'm opening them by means of CrossApplicationNavigation. they open new tab.

on my main app, I implemented a button to close every tab and returning to root view.

I tried the following : Script to close other tabs or browser

here is my code :

            var oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation");
            var oExtUi = oEvent.getSource().getText();
            var hash = oCrossAppNavigator.hrefForExternal({
                target: {
                    semanticObject: "ZSIMM_PDL",
                    action: "display"
                },
                params: {
                    "UtilitiesPDL": oExtUi
                }
            });
            var url = window.location.href.split("#")[0] + hash;
            this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
            this._myModel = this._oComponent.getModel("oModelWindow");
            this._myModel.setProperty("/Window", window);
            sap.m.URLHelper.redirect(url, true);
        },   

this way, i open the new tab with my semanticObject. and I register it in my Model.

the next step is the method linked with my button :

            this._myModel = this._oComponent.getModel("oModelWindow");
            var aWindow = this._myModel.getData().Window;
            aWindow.close();    

I'm loading the window of the tab I opened. the instruction close doesn't work it writes : "Scripts may close only the windows that were opened by it."

what I understand in CrossApplicationNavigation is that it opened a new tab and redirect by use of sap.m.URLHelper.redirect(url, true); does the current screen before calling the new one know which page it opens ? and this way is there a method to close it manually ?

1 Answers1

0

I found a solution which is the following : when opening the crossApplicationnavigation, I put on memory the tab opened :

            var oExtUi = oEvent.getSource().getText();
            var hash = oCrossAppNavigator.hrefForExternal({
                target: {
                    semanticObject: "ZSIMM_PDL",
                    action: "display"
                },
                params: {
                    "UtilitiesPDL": oExtUi
                }
            });
            var url = window.location.href.split("#")[0] + hash;
            this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
            this._myModel = this._oComponent.getModel("oModelWindow");
            var aWindow = this._myModel.getData().Windows;
            aWindow.push(window.open(url, "_blank"));
            this._myModel.setProperty("/Windows", aWindow);

and in the button method, I recall all tab and close them all this way :

            this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
            this._myModel = this._oComponent.getModel("oModelWindow");
            //then you can iterate over them and close them all like this:
            var oWindow = this._myModel.getData().Windows;

            for (var i = 0; i < oWindow.length; i++) {
                oWindow[i].close();
            }

that way when clicking the button all other tab are closed.