3

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?

6
  • 1
    Did you use Javascript to open the window? Javascript can only close windows that were opened using Javascript. Mar 13, 2012 at 11:24
  • For whoever will answer, please, consider XPiNC. Mar 13, 2012 at 12:04
  • @jjtbsomhorst: Actually it is home page of sample webpage. So, Let me know Is their any way to do this...
    – Ramkumar
    Mar 13, 2012 at 12:31
  • 1
    In Chrome and FF you can specify in a setting if window.close() would be supported. If that's off, then it is off.
    – stwissel
    Mar 13, 2012 at 13:14
  • 1
    I would rather NOT to use javascript to manipulate things out of the page context. There are too much OS, too much browsers with too much versions and too much functions, to make it work everywhere. This is the way of 90'.
    – JiKra
    Mar 13, 2012 at 13:19

5 Answers 5

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)
1
  • :Thanks for your Response, Every time it is moved to catch, This is also not working.,
    – Ramkumar
    Mar 16, 2012 at 4:14
2

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>
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.

0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.