Closing a browser window from a javascript link

I am trying to set up a link to close a browser window using: onClick="javascript:window.close();

The window is initially opened from the main page and displays a signup form. When the form is sent a confirmation page appears and it is this page that has the button to close the window using the javascript function above.

The javascript works if I open the window directly to display the confirmation page but it is not working when the confirmation page is called from the original page with the form.

Could someone point me in the right direction please.
grigorovskyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
grigorovskyConnect With a Mentor Author Commented:
The confirmation page appears in the same window as the sign up form and has the close button at the bottom. Apologies if that wasn't clear from my original post.

I originally had the confirmation page script set to window.close() and this didn't work. It appears that parent.close() is the correct method in this situation.
0
 
MrunalCommented:
Hi
Can you post your code? This can help us to resolve your problem quickly.
0
 
Barry62Commented:
Use self.close()

<a href="" onclick="self.close();return false;";>Close This window</a>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
grigorovskyAuthor Commented:
Self.close() doesn't work either but I have now discovered that parent.close() does.
0
 
Barry62Commented:
hmm.  I thought you were wanting the button on the confirmation window to close itself, not the main form window.
0
 
grigorovskyAuthor Commented:
This works:

<a href="#" class="button" onClick="javascript:parent.close();">Close Window</a>

These don't:

<a href="#" class="button" onClick="javascript:self.close();">Close Window</a>
<a href="#" class="button" onClick="javascript:window.close();">Close Window</a>
0
 
Barry62Commented:
Yes, that would be correct in your situation.  Sorry for the misunderstanding.
0
 
grigorovskyAuthor Commented:
My own solution was the correct one in this situation.
0
All Courses

From novice to tech pro — start learning today.