Sourav Das Sourav Das - 1 year ago 143
HTML Question

Closing a Parent Window after Modal is closed in JQuery

I am trying to close the Parent Window when a Modal Window is Closed.
I created a custom Modal Window using JQuery UI and i am not able to close the parent window.

$(document).ready(function () {
dialog = $("#dialog").dialog({
autoOpen: false,
height: 300,
width: 500,
modal: true,
buttons: {
"Approve": addUser,
Cancel: function () {


function addUser() {

var getJSON = function (url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();'get', url, true);
xhr.withCredentials = true;
xhr.onload = function () {
var status = xhr.status;
if (status == 200) {
} else {

getJSON(url).then(function (data) {
var result = "Approved Successfully"
window.close(); ///Here, the PARENT Window is not closing

}, function (status) { //error detection....
alert('Something went wrong.');

Here, my Modal Box is closing but window.close() is not closing the parent window.

I am getting an Message "Scripts may close only the windows that were opened by it."

How to solve this issue.


Answer Source

Create function in parent window

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download