UID
UID

Reputation: 4514

How to close a window from button in JQuery UI dialog box

I want to close the current window with the click of a button, inside a JQuery UI dialog box.

I tried with window.close():

$(document).ready(function() {
  $("#sessionReason").dialog({
    autoOpen: false,
    modal: true,
    buttons: {
      "Submit": function() {
        window.close();
      },
      "Cancel": function() {
        $(this).dialog("close");
      }
    }
  });
  $("#cancelSessionButton").click(function() {
    $("#sessionReason").dialog("open");
  });
});
<!DOCTYPE html>
<html>
<head>
  <title>jQuery UI Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
</head>
<body>
  <input id="cancelSessionButton" type="button" value="Cancel Session" class="redButton" />

  <div id="sessionReason" title="Reason">
    <p>Please provide the reason for cancelling the session.</p>
    <div class="inputRow">
      <textarea id="sessionReasonBox" class="reasonBox"></textarea>
    </div>
  </div>
</body>
</html>

http://jsfiddle.net/d3bxM/

Upvotes: 1

Views: 4061

Answers (1)

Krish R
Krish R

Reputation: 22721

Did your script open the window? Firefox 2 and later do not allow scripts to close windows that they did not open. window.close();

This method is only allowed to be called for windows that were opened by a script using the window.open method.

Upvotes: 1

Related Questions