How do I close a window in Xpage?

Actually I am using the following code to close my current window:



The thing is, it works fine in IE, but it doesn't work in FF and Chrome.

Is this a great solution for this?


source to share

5 answers

window.close () works in 8.5.3, but only if the parent contains the object, and it won't if you have an xpage that opens inside a regular Notes application or a regular view. you need a .open window to get this.

I talked about this for a long time, but did not find an answer. The only way I have found is that you need the Mindoo XPage2Esclipse plugin to get it working.



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


Used like:





I found a partial solution, Java is your friend. It works in a button, should work in a link too. The only problem is being called from an event like onClose when the current xpage loses focus and the current pages remain open. I tried to mimic the submit keys and pressed the ESC key. It works great with a button. Button on CLick event

<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        <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






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



I have been using window.close without issue in 8.5.3 apps with Chrome / FF / IE.

On the main page of the Business Document application, I have some CSJS at the top that names the page, i.e."mainWindow";


and then I have a button that lets me ask a question - this pops up a new window / tab and keeps opening the main file. The new window has a submit button that does a full refresh, and in the onComplete event I have the following CSJS to update the main document so you can see the question on the main document in the redo controller that shows the Q and Docs streams:

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


Hope it helps



All Articles