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?

Improve company productivity with a Business Account.Sign Up

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.