Closing a browser window from a javascript link

Posted on 2013-01-23
Medium Priority
Last Modified: 2013-01-28
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.
Question by:grigorovsky
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 22

Expert Comment

ID: 38810338
Can you post your code? This can help us to resolve your problem quickly.

Expert Comment

ID: 38810363
Use self.close()

<a href="" onclick="self.close();return false;";>Close This window</a>

Author Comment

ID: 38810852
Self.close() doesn't work either but I have now discovered that parent.close() does.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 38810861
hmm.  I thought you were wanting the button on the confirmation window to close itself, not the main form window.

Author Comment

ID: 38810867
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>

Accepted Solution

grigorovsky earned 0 total points
ID: 38810891
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.

Expert Comment

ID: 38810985
Yes, that would be correct in your situation.  Sorry for the misunderstanding.

Author Closing Comment

ID: 38826195
My own solution was the correct one in this situation.

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question