-
-
Save nextroy/3003866 to your computer and use it in GitHub Desktop.
$(document).ready(function() { | |
// Support for AJAX loaded modal window. | |
// Focuses on first input textbox after it loads the window. | |
$('[data-toggle="modal"]').bind('click',function(e) { | |
e.preventDefault(); | |
var url = $(this).attr('href'); | |
if (url.indexOf('#') == 0) { | |
$('#response_modal').modal('open'); | |
} else { | |
$.get(url, function(data) { | |
$('#response_modal').html(data); | |
$('#response_modal').modal(); | |
}).success(function() { $('input:text:visible:first').focus(); }); | |
} | |
}); | |
}); |
<a href="/url/to/load/modal_window.htm" data-toggle="modal">link</a> | |
<div id="response_modal" class="modal hide fade"></div> |
<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> |
btw.. removed the dirty fix :P .. that was way to dirty.. i agree
Not to worry. I think our connection at the office is being slow today. Sorry. I'm sure performance is identical with both approaches. Much prefer the href approach too. Thanks again!
Your Modal works but if you put code below in the doal body that will open new page instead modal window:
<script type="text/javascript"> var ids = 'text'; document.write(ids); </script>code:
<script type="text/javascript">
var ids = 'text';
document.write(ids);
</script>
Does line #9 make sense? Won't this just open an empty modal rather than the div with the ID specified in the href like standard Bootstrap?
Small problem with this. I've got an addthis code in the modal. It loads for the first opening but not any others after
Editar
var url = $(this).attr('rel');
loading page with many objects is slow using modal from my end
Does it even work? Adding a link for jsfiddle or jsbin would really help
Keeping it with href is the sensible approach .. as far as the load times are concerned.. i don't think it should affect that.