Skip to content

Instantly share code, notes, and snippets.

@letunglam
Forked from drewjoh/custom.js
Created July 9, 2012 06:25
Show Gist options
  • Save letunglam/3074561 to your computer and use it in GitHub Desktop.
Save letunglam/3074561 to your computer and use it in GitHub Desktop.
Dynamic (AJAX) loaded Bootstrap Modal (Bootstrap 2.0)
$(document).ready(function() {
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').click(function(e) {
e.preventDefault();
var href = $(this).attr('href');
if (href.indexOf('#') == 0) {
$(href).modal('open');
} else {
$.get(href, function(data) {
$('<div class="modal" >' + data + '</div>').modal();
}).success(function() { $('input:text:visible:first').focus(); });
}
});
});
<a href="/url/to/load/modal_window.htm" data-toggle="modal">link</a>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header 2</h3>
</div>
<div class="modal-body">
<p>One body...</p>
</div>
<div class="modal-footer">
<a class="btn btn-primary">Save Changes</a>
<a class="btn" data-dismiss="modal">Close</a>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment