How do I close my window in Xpage?

2019-01-28 07:31发布

问题:

Actually I am using the following code for closing my current window:

window.close()

The thing is, it is working fine in IE, but it is not working in FF and Chrome.

Is their any great solution for doing this?

回答1:

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.



回答2:

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)


回答3:

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>


回答4:

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



回答5:

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