How do I close my window in Xpage?

血红的双手。 提交于 2019-11-29 15:10:34

window.close() works in 8.5.3 but only if parent contains an object and it will not do this if you have i.e an xpage that is opened inside an ordinary Notes application or a ordinary view. you need a window.open to get this.

I have investigated alot about this a while ago but no luck finding an answer. The only way I found is that you need the Mindoo XPage2Esclipse plugin to get this to work.

function windowclose(w) {
    try {
        if (dojo.isIE>=7) {
            w.open('', '_self', '');
            w.close();
        } else if (dojo.isIE==6) {
            w.opener = null;
            w.close();
        } else {
            if(!w.opener)
                w.opener = 'x';
            w.close(); 
        }
    } catch(e) {
        alert("To avoid data corruption/loss, please close this window immediately.");
    }
}

To be used as:

windowclose(window)

I found a partial solution, Java is your friend. It works in a button should work in a link too. The only problem is when called from an event like onClose the current xpage looses focus and the current pages stays open. I tried to emulate send keys and it presses the ESC key. It works fine from a button in. Button on CLick event

<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript:var robot:java.awt.Robot= new java.awt.Robot;var event:java.awt.event.KeyEvent=java.awt.event.KeyEvent;

robot.keyPress(event.VK_ESCAPE); robot.keyRelease(event.VK_ESCAPE); enter code here}]]>

    </xp:eventHandler>
</xp:button>

You may have to call window.focus() before calling window.close() in Firefox

I use window.close with no problems in 8.5.3 apps with Chrome / FF / IE.

In the main page of an app, the "Case Document" I have some CSJS at the top that names the page ie.

window.name="mainWindow";

and then I have a button that allows you to ask a question - this pops up a new window/tab and keeps the main case doc open as well. In the new window, there's a submit button that does a full update and in the onComplete event I have the following CSJS to update the main doc so you can see the question on the main doc in the repeat control that shows the threads of Q & A docs:

    if (window.opener!=null){
        window.opener.location.href = window.opener.location.href; 
        window.close();}
    else {
        alert("Can't refresh parent case doc - have you closed the window?");
    }

Hope this helps

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