How can I automatically close the form after submitting?


#1

I have one form page… after the client submits their info i want the form to close the window (it opens in a new browser menu)


#2

Hi Sharbel, just to be clear on what you’re trying to accomplish: Are you opening your Unbounce page in a pop up window, and hoping to automatically close the window after the form has been submitted?


#3

Hello Carter, Yes that is correct


#4

There’s no built-in way to do that yet, but you could try this:

  1. Make sure the form confirmation is set to “Show form confirmation dialog”.
  2. Edit the Confirmation Dialog (click on the tab at the top of the window)
  3. Click on the “Scripts” tab and add this:
\<script type="text/javascript"\>  
top.window.close();  
\</script\>  
  1. Make sure the script “placement” dropdown is set to “Head”.

Now as soon as the form submits, it will open the popup and execute the window.close() command. If you want the confirmation message to show for a couple seconds, you could use this script instead (the 2000 will be 2 seconds):

\<script type="text/javascript"\>  
setTimeout("top.window.close()", 2000);  
\</script\>  

Hope that helps!


#5

Hi,

this solutions seems to be exactly what I need, except I don’t seem to get it working.
I don’t know a thing about writing code, and I’ve tried a couple of ‘variants’ of the piece of code above, but none of them seem to close the window…
I tried:

Can you help me out?


#6

right, code isn’t showing :slight_smile:

I tried to replace the < by < and the > by > but nothing happens…


#7

Hi Dimitri,

Can I ask you to clarify on exactly what you’re trying to achieve?

Like Sharbel, are you trying to close the entire window that the landing page is in? If so, the script above should work. This is the fixed version you could try:

setTimeout(function(){ <br />
  top.window.close() <br />
}, 2000); <br /> </script>```   
 
Or, are you trying to keep the page itself open but **just close the form confirmation dialog**? I think this is a more common use case, but the code above won't do that for you. If that's what you're looking for, please let us know and we can share a script with you.   
 
Thanks!

#8

Hi,

what I do is the following: I open an unbounce form as a pop-up on my website.
Once the form is filled out a thank you message appears.

I would like to close:

  • the form once the thank you message appears
  • close the thank you message after 2 sec

Hope that makes sense, if not, this is the page I’m using it on:
http://energievergelijker.tariefcheck…
after 90 sec (or when you click on the button at the bottom right) the form pops up.

thx for your quick response,

sincerely,

Dimitri


#9

Hello Dimitri,

If you’re opening the Unbounce page in an IFrame popup (like a lightbox), then the parent page will be the only one that could close the popup.

This is because your Unbounce page, in an IFrame, won’t have any access to its parent page. This means it won’t be able to call the JavaScript function to close itself.

Therefore, you’ll need to look into JavaScript solutions for closing a lightbox from its parent page, once a user has been taken to the thank you page.

An easier alternative may be to use browser windows instead of IFrames. This way, you can simply use the script that I posted on the 31st to close the window 2 seconds after the ‘thank you’ page has loaded. However, you’ll also need to be wary of pop-up blockers if you go down this route.

Hope that helps!


#10

yes that’s great, thank you!


#11

Hello Could you please share the script to close thank you message :slight_smile:


#12

Thank you