Skip to content

Instantly share code, notes, and snippets.

@IAMIronmanSam
Created July 24, 2016 20:45
Show Gist options
  • Save IAMIronmanSam/a2bb0886264bc3cdf504ee955f270ce0 to your computer and use it in GitHub Desktop.
Save IAMIronmanSam/a2bb0886264bc3cdf504ee955f270ce0 to your computer and use it in GitHub Desktop.
Bootstrap modal dialog generator
function bootstrapModelDialog(id, title, body, buttons) {
try {
if (!document.getElementById(id)) {
var innerHtml = "<div class=\"modal fade\" id=\"" + id + "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"basicModal\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button><h2 class=\"modal-title\" id=\"myModalTitle\">" + title + "</h2></div><div class=\"modal-body\" id=\"modalBody\">" + body + "</div><div class=\"modal-footer\" id=\"modalFooter\">" + buttons + "</div></div></div></div>";
$("body").append(innerHtml);
$('#' + id).modal('show');
} else {
$('#myModalTitle').html(title);
$('#modalBody').html(body);
$('#modalFooter').html(buttons);
$('#' + id).modal('show');
}
} catch (ex) {
console.error(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment