1

I am having a Xpage with some links. One of my link call EXIT having window.close() to close the current tab in browser.

In browser when I am opening the document(Xpage holds the document) from the view and clicking on the EXIT link, it closes the current tab/window.

Whereas, I am redirecting the same xpage from SSJS using context.redirectToPage() . When I clicking on the EXIT link, it is not closing the tab/window.

In Javascript console: Scripts may not close windows that were not opened by script

Anyone help me.

Thanks in Advance, Karthick

flykarthick
  • 79
  • 1
  • 6
  • 14

3 Answers3

5

As the Javascript console says: Window.close() needs a window.open() to work.

See http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Whats_New_in_852_for_XPages#window.close%28%29+support

Update: You can create your response document using client-side JS - including opening the window. The following will do that:

// get parent document id    
docid='#{javascript:document.getNoteID()}';

// create the URL
url="response.xsp?action=newDocument&parentId="+docid;

// open a new window with the response document
window.open(url);
Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
  • I am creating a response document for the current document when clicking on the link. The only way is that I have redirected the page. So any other solution to make is work...? – flykarthick Apr 11 '12 at 12:46
  • Thanks... I will try this out... Whereas I am pushing more than 65 field values from parent document to response document before opening, so that I went for SSJS... I will try pushing those values in afterPageLoad of the response document... Any other simpler way to do this...? – flykarthick Apr 12 '12 at 05:12
  • You could look at creating the response document in a dialog in order to avoid opening a new window. Good luck with your solution. – Per Henrik Lausten Apr 12 '12 at 06:43
3

"In Javascript console: Scripts may not close windows that were not opened by script"

Thats you're answer to the question. Javascript can't close tabs / windows which are not created by javascript.

You could try the following:

How to close browser window

jjtbsomhorst
  • 1,667
  • 11
  • 28
0

you can try this trick im using.

window.open('', '_self', '');

window.close();
songyuanyao
  • 169,198
  • 16
  • 310
  • 405