Solved

Closing a browser window from a javascript link

Posted on 2013-01-23
8
340 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now