How do I close a window in Xpage?
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.
source to share
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.");
}
}
Used like:
windowclose(window)
source to share
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"
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>
source to share
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.
window.name="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;
window.close();}
else {
alert("Can't refresh parent case doc - have you closed the window?");
}
Hope it helps
source to share