On my website I open a modal / dialog with JavaScript, how ever when the user clicks on another tab on the same view the modal will still be there and be in the way. So if the user clicks of the modal I would like to close it. But I am not sure how to do it, I know the OnBlur attribute but I haven't come up with a solution that works just yet. This is my script:
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
height: 220,
width: 305,
modal: true,
buttons: {
'Spara': function () {
if (!validateNumber()) {
alert('Procent måste vara mellan 0-100');
return false;
}
if (!validateProject()) {
alert('Du måste välja ett project');
return false;
}
if (!validateDate()) {
return false;
}
locstring = "@(Url.Action("Index"))/Update/?";
locstring += '&projectId=' + $('#projectList').val();
locstring += '&startDate=' + $('#startDate').val();
locstring += '&endDate=' + $('#endDate').val();
locstring += '&pct=' + $('#pct').val();
var sid = $('#sId').text();
if (sid !== "") {
locstring += '&id=' + sid;
}
$.ajax({
type: "GET",
url: locstring,
dataType: "html",
success: function (data) {
$('#dialog').dialog('close');
reloadTable();
}
});
},
'Avbryt': function () {
$(this).dialog('close');
},
'Ta bort': function () {
var sid = $('#sId').text();
if (sid != "") {
locstring = "@(Url.Action("Index"))/Delete/" + sid;
$.ajax({
type: "GET",
url: locstring,
dataType: "html",
success: function(data) {
$('#dialog').dialog('close');
reloadTable();
}
});
}
}
},
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});
$('#create-user').click(function() {
$('#dialog').dialog('open');
})
.hover(
function() {
$(this).addClass("ui-state-hover");
},
function() {
$(this).removeClass("ui-state-hover");
}
).mousedown(function() {
$(this).addClass("ui-state-active");
})
.mouseup(function() {
$(this).removeClass("ui-state-active");
});
});