fd.spSaved isn't closing the window

We are opening our list items in a separate tab directly from the modern list web part. We do this by clicking on one of the fields (summary) that has this format code.

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField",
"attributes": {
"target": "_blank",
"href": "='/sites/HIT/Lists/CBO%20HIT%20Support%20Tickets/EditForm.aspx?ID=' + [$ID]"
}
}

We then want that new tab to be closed when we save the form. So we have this code below in our form. This used to work correctly, but for some reason has stopped working sometime in the past several months. The result is that it closes the form, but leaves the tab open and redirects to the list view (not the original page opened from, but just a plain list view for the entire list)

fd.spSaved(function() {
window.close();
});

Can someone help me with this? Again, it used to work, and this is, I believe, a tip we got last year from Plumsail on how to do this very thing.

Thanks in advance,
Gary Griffin

Dear @CBOI_GGriffin,
Hmm, is the code even running? Have you tried something like this:

fd.spSaved(function() {
  alert('Closing!');
  window.close();
});

If you see the alert message, but it's not closing - then the change has nothing to do with the forms, it might connected to the browser you use and its settings/updates.

You can always redirect users to some page directly like this:

fd.spSaved(function() {
  alert('Closing!');
  window.location.href = 'https://plumsail.com/';
});

This is very interesting. I've added the line of code to my form and now I get a pop up from Google Chrome that says "Closing!" and when I click ok, it closes the tab as expected. I know that line of code only produces the pop-up, but adding it somehow allows for the second line to work, thus closing the tab.

Any reason why adding this would allow the code to execute properly? And is there a way I can get th code to work, but not have the pop-up?

Thanks!
Gary

I spoke too soon. The first couple of test did indeed close the tab. However, now that I'm actually using it and filling in fields, when I click on save, it gives the pop-up, and then doesn't close the tab, but re-directs me back to the default list view.

Having it direct it back to another page isn't an option because as they open tickets up and try to "close" them, they will end up with a multitude of tabs open.

Also, in further testing, I removed the window.close line and added your line to re-direct back to the original page and it too looks like it's being ignored, however the pop-up always seems to work.

Any thoughts?
Gary

Ok, I think I figured out why it works sometimes and why it doesn't other times. If I have Google Chrome open and have only ONE tab open and click on the list item, which then opens it in a SECOND tab (but I don't have any other tabs open, just the two), when I click on Save to save the form, it will save the form and close that second tab.

If, however, I have multiple tabs open, when I click on SAVE, it will save the form and close the form, but not close the tab. Instead, it will redirect that tab back to the default list view.

We need it to close the tab that the form is open in. That would allow us to open a "ticket" (list item using a plumsail form) in a new tab, modify the ticket, save the ticket, and have it close that tab, thus leaving the original dashboard open to continue manipulating tickets, etc.

Sorry for all the responses this morning, just trying to work through this since multiple people use it.
-Gary

Dear @CBOI_GGriffin,
The issue with closing a tab with JavaScript is that it's quite an intrusive behavior and can be seen as potentially malicious by the browser. There are some hacks that can be used to close the tab somewhat reliably, but it also depends on the browser used and would potentially be fixed in future updates. Read more about it here, maybe one of the methods described will work for you - javascript - window.close and self.close do not close the window in Chrome - Stack Overflow

a new strange behavior here, in the display form the code works properly but in the edit form window.close() does nothing.
any help regarding this issue.

Dear @MehmetMuhanna,
Are you sure the code is running? You can try adding a console log command, and then checking the console to see if it ran:

console.log('Closing!');
window.close();

i did that, i have used the alert command and the message is popping up, but the window.close() is not working.

Dear @MehmetMuhanna,
Does the form open in full screen or in panel? Any difference with Display form?

I would be very interested to hear is there is any reliable solution to this.
I am using edge and

fd.spSaved(function(result) {
    window.close();
});

is not doing anything. I have the form set to open in fullscreen (new tab) and want to close the tam after submission.
As Nikita noted: "would potentially be fixed in future updates" maybe there was some development.
Looking around the Plumsail community it seems that everyone is looking for solutions on how to open a different page, redirect to elsewhere, but no one wants to close the tab! :slight_smile:
I am using Edge,

Hello @HypnoToad,

How do you open the page?

For me the code works if the tab is opened using the window.open() function.

My form is set to open New item in "full screen". So when I click Add item in my Sharepoint list it opens a new tab.

Thanks for your help with this.

@HypnoToad,

Not much we can suggest here. You can close the tab programmatically with window.close() method only if it were opened by a script using the window.open().