window.close() in XPages - lotus-notes

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

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);

"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

you can try this trick im using.
window.open('', '_self', '');
window.close();

Related

Chrome Extension "run_at" page close?

What options do you have when using run_at in your extension manifesto?
I'm ideally looking for a content script to be run when a page from a specified website is closing down. Just so I can save how far the user had scrolled down.
Any idea how I might manage this?
You can use the content script to listen to the window onbeforeunload event and add your logic in the callback. This fires when user navigates away from the page. I'm assuming this is what you mean by "closing down".
In addition to the peterdotjs answer, you can use the chrome.tab.onRemoved event

Is it possible to save a file using client side javascript in xpages

I customize my confirmation prompt using sweetAlert, I did it, now my problem is using a customize confirmation prompt, I cannot use SSJS code but I need to save a document with a file upload.
I need Help with this thanks!
My workaround for this is an XPoages button that contains the required SSJS code for saving the document. The button resides in a hidden normal DIV (style="display:none"). When executing you CSJS just refer to the clientId of that button and fire the event click() like in
function csjsAction(){
dojo.byId("#{id:yourButton}").click();
}

context.redirectToPage only works intermitently in Notes Client

I have a button in an Xpage with an OnClick event that does the following:
var viewPanel=getComponent("viewPanel1");
var docIDArray=viewPanel.getSelectedIds();
sessionScope.put("searchDocIDArray",docIDArray);
var url="exportData.xsp";
context.redirectToPage(url, false);
The exportData page is not rendered but just has some code to write out an Excel file. In the client sometimes it does this and sometimes it does nothing and sometimes it writes over the current Xpgage and is just blank. I think what I need to do is to just launch that page in a new window? I am not sure.
It works on the web every time.
What version is your client?
Another approach you can try is opening your xagent with a window.open () in the onComplete event of your button. I don't remember off the top of my head if that works in xpinc. The advantage of this is your export will open in a new tab.

How do a Chrome Extension background.html access the current window (user's content window)

chrome.windows.getCurrent only gets me the background.html itself. What I really want is the content window that the user is browsing.
Any tips for this, thanks!
The current window is the window that contains the code that is currently executing. It's important to realize that this can be different from the topmost or focused window.
For example, say an extension creates a few tabs or windows from a single HTML file, and that the HTML file contains a call to chrome.tabs.getSelected. The current window is the window that contains the page that made the call, no matter what the topmost window is.
If you want to get content window what user is browsing you can use following code:
popup.js
chrome.windows.getAll({"populate":true},function (windows){
for(i=0;i<windows.length ;i++){
if(windows[i].focused){
for(j=0;j<windows[i].tabs.length;j++){
if(windows[i].tabs[j].selected && windows[i].tabs[j].active && windows[i].tabs[j].highlighted ){
console.log(JSON.stringify(windows[i].tabs[j]));
}
}
}
}
});
Why not use chrome.windows.getLastFocused()?

Open and pass data to a popup (new tab) from content script

I'm writing a chrome extension and have a question.
My extension has some .html page in it, let it be 'popup.html'. I inject a content script into some page and this script opens a 'popup.html' in a new tab with something like 'var p = window.open(chrome.extension.getURL('/popup.html'), "popup")', which works perfectly. Next, I need to pass some data to this window and I can't figure how to do it in a simple way.
For some reason I can't call child window's function from a content script with
var p = window.open(chrome.extension.getURL('/popup.html'), "popup");
p.foo(data);
In the console I see Uncaught TypeError: Cannot call method 'foo' of undefined message.
I can't pass data in a query string, because the data is simply too big.
Is there an elegant and simple way to pass data to such kind of window? I thought about messaging, but how do I effectively get tab ID of a newly opened window w/out using a background page?
Thanks a lot in advance.
UPD:
I tried to inverse the logic and get a data from parent window with 'window.opener.foo()' but in a newly opened tab window.opener returns null.
Ok, I found two solutions to my problem.
1) Add a background page, which opens a popup with chrome.tabs.create(). Then send a message from a content script to a background page, which re-sends it to a corresponding tab via chrome.tabs.sendMessage(). It looks a little ugly, but works.
2) A better one, w/out background page. Extension (popup) page creates a listener for long-lived connection. Then content script sends a message to this connection. A problem here is that a listener is not created right after the page is opened, so there should be a mechanism for a content script to wait until popup is loaded. It can be a simple setTimeout or a notification from popup via same long-lived connection.
If anyone has a better solution I'd gladly check it out as well.

Resources