user3747449_Santhosh
user3747449_Santhosh

Reputation: 121

The Window.close(); is not working in Chrome and Mozilla Firefox

My application sends an e-mail to the manager with an approve and a reject button

I tried to close the window, i.e, already open. The fallowing ways

var win = window.open('','_self');
win.close();

window.top.opener=null;
window.close();

var win=window.open("","_self");
win.close(); 

window.open('','_parent',''); 
window.close();

The above did not work. Can someone provide a solution for this.

Thank you in advance. Please don't close this. Because i googled lot, I did not find solution.

Upvotes: 1

Views: 1328

Answers (2)

Margus
Margus

Reputation: 20038

I would use jQuery UI component Dialog.

 $(function() {
    $( "#dialog" ).dialog();
  });
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>


You get that error message because outlook redirects link clicks to a new browser instance. After it is opened he has no control over it.

You can close pages that it opens, but you definitely can not close browser instance itself.


If you send it via email then depending of mail viewer you have limited support. Ex: gmail strips away html head, body, all non inline css and javascript. In short : jQuery UI Dialog would not work.

Instead use a link with get parameters (ex: unique user id) and read it when page is opened.

Upvotes: 1

JNF
JNF

Reputation: 3730

See MDN on window.close():

This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

Upvotes: 3

Related Questions