Save & Close Window

  • 2
  • 1
  • Question
  • Updated 1 year ago
  • Answered
I am trying to figure out how to create a Save & Close Window button. I have a formula - URL button that opens to a QB form in a new window that works fine using this javascript: 

& " 'URLHERE' ,' ', 'top=50,left=220,width=800,height=700,location=no,menubar=yes,toolbar=no,resizable=1,scrollbars=yes,resizable=yes,toolbar=no'))"

I also have a Save & Keep Working formula-URL button that triggers fine in the pop up window:
URLRoot() & "db/" & Dbid() & "?a=er&rid=" & [Real Estate Project ID#]& "&dfid=53&ifv=1"

However, I want to create a button that will  1) first save the form and then 2) close the  window. 
I can run the window.close() scriptfine on its own, but I don't know how to get the two to run sequentially.  

P.S. I don't know much javascript -- I'm learning as I go. Any help is much appreciated. 
Photo of QB Development

QB Development

  • 330 Points 250 badge 2x thumb

Posted 1 year ago

  • 2
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
You will need to utilize the 'linkaway' function, to an html code page that closes the window.

Then if you and to have the 'reload' action come from the original tab / button.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
Is this what you are asking for?

Click a button in the first window, open a new second window (say to a=nwr page), add the new record in the second window and when that second page submits close the second window - all seamlessly.

If that is what you want it can be done but it has to be done in a vary particular way as script cannot close a window it did not open. So the script to orchestrate this has to be set up exclusively in the first window  where the button initiating the action is.

Please confirm or clarify further.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
I just want to get this script out of my editor so here goes. This essential script when invoked from a button click will open a new window specified by the variable urlNew and monitor changes to that second window's URL. So when a user submits the form on that second window or navigates away from the original URL of the second window, the script running in the first window will close the second window automatically.  
var urlNew = "https://<SUBDOMAIN><DBID>?a=nwr";
var mywin =;
var monitor = setInterval(function() {
  console.log(mywin.location.href) ;
  if (mywin.location.href != urlNew) {
}, 1000);

This is sort of an old-school navigational scheme that has fallen out of favor but may still be useful when you have a longish form to fill out and a dialog box in the first window would be to small.

Pastie Database
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
Okay I implement this. Visit the following application and follow the instructions:

(1) Click on the blue button labeled "Open Sesame & Edit" on a Sesame seed record

(2) Add your comment to the Notes field (it is the only field you can edit)

(3) Click the Save button modified to read "Save & Close Sesame"

After these three steps the following will happen:

(1) the record you were editing will be saved with your worthy comment

(2) the page you were editing will automatically close

the page you started from where you click the  "Open Sesame & Edit" will reload.

Open Sesame / Close Sesame

Pastie Database


(1) It is subtle to understand the workflow of this example but it might be very useful to those users that temporary open up a number of tabs to create a "to do list" and when the data entry or other work on that page is completed and the page saved or navigated away from the window automatically closes. You can't get script to close a page unless the script opened a page in the first place (it is a security thing). So the script running the the first page is responsible for monitoring changes in the second page and when the URL of the second page changes the second window is close the the first page reloads.

(2) This technique can be used for a variety different tasks - the one I picked of editing records was just for the demo.

(3) I call this technique the Open Sesame & Close Sesame technique

(4) The technique is of course named after the folk tale Ali Baba and the Forty Thieves which if you are into Folkloristics as I am is canonically represented as ATU-676: according to the Aarne-Thompson-Uther Classification of Folk Tales:

Aarne-Thompson-Uther Classification of Folk Tales–Thompson_classification_systems

ATU 676: Open Sesame!

(5) I am gonna go get some bagels now ...