Solved

Closing a browser window from a javascript link

Posted on 2013-01-23
8
342 Views
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.
0
Comment
Question by:grigorovsky
[X]
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
8 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 38810338
Hi
Can you post your code? This can help us to resolve your problem quickly.
0
 
LVL 8

Expert Comment

by:Barry62
ID: 38810363
Use self.close()

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

Author Comment

by:grigorovsky
ID: 38810852
Self.close() doesn't work either but I have now discovered that parent.close() does.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

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

Author Comment

by:grigorovsky
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>
0
 

Accepted Solution

by:
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.
0
 
LVL 8

Expert Comment

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

Author Closing Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 7 to Windows 10 and back. IE 9.0, 10.0, 11.0 10 64
Getting selected value using Jquery 3 20
Echo'd values in dropdowns 6 29
Boolean 13 21
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

749 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