Solved

Closing a browser window from a javascript link

Posted on 2013-01-23
8
343 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
RoboForm Secure Password Management System

RoboForm Everywhere - Superb Browser Support
Windows / Apple / IOS / Android / Linux / Chrome OS
Use different complex passwords everywhere
Best Secure Password Management by far
Synchronize all of your devices instantly
Safe, Secure & Highly Recommended!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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.
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.

742 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