This is the solution i have adopted. It works with:
- jQuery v1.11.2
- jQuery Migrate v1.2.1
- Bootstrap v3.3.1
Main page HTML:
<!doctype html> <html class="no-js" lang=""> <head> <!-- Your code here --> </head> <body> <ul> <li><a href="/page-1" data-target="bs-modal-lg" class="modal-trigger" data-toggle="modal">Modal page #1</a></li> <li><a href="/page-2" data-target="bs-modal-md" class="modal-trigger" data-toggle="modal">Modal page #2</a></li> </ul> <div class="modal fade bs-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"></div> </div> </div> <div class="modal fade bs-modal-md" tabindex="-1" role="dialog" aria-labelledby="myMediumModalLabel" aria-hidden="true"> <div class="modal-dialog modal-md"> <div class="modal-content"></div> </div> </div> <div class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"> <div class="modal-dialog modal-sm"> <div class="modal-content"></div> </div> </div> <!-- Javascript here --> </body> </html>
Modal page #1 HTML:
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> <h4 class="modal-title" id="myLargeModalLabel">Modal page #1</h4> </div> <div class="modal-body"> <ul> <li><a href="/" target="_parent">Main page</a></li> <li><a href="/page-2" data-target="bs-modal-md">Modal page #2</a></li> </ul> </div>
Modal page #2 HTML:
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> <h4 class="modal-title" id="myLargeModalLabel">Modal page #2</h4> </div> <div class="modal-body"> <ul> <li><a href="/" target="_parent">Main page</a></li> <li><a href="/page-1" data-target="bs-modal-lg">Modal page #1</a></li> </ul> </div>
Bootstrap 3 Modal Vertically Centered (see here http://codepen.io/ahliang85/pen/aFteG/):
(function($) { $.extend({ adjustModalMaxHeightAndPosition : function(focus) { $('.modal').each(function(){ if($(this).hasClass('in') == false){ $(this).show(); }; var contentHeight = $(window).height() - 60; var headerHeight = $(this).find('.modal-header').outerHeight() || 2; var footerHeight = $(this).find('.modal-footer').outerHeight() || 2; $(this).find('.modal-content').css({ 'max-height': function () { return contentHeight; } }); $(this).find('.modal-body').css({ 'max-height': function () { return (contentHeight - (headerHeight + footerHeight)); } }); $(this).find('.modal-dialog').css({ 'margin-top': function () { return -($(this).outerHeight() / 2); }, 'margin-left': function () { return -($(this).outerWidth() / 2); } }); if($(this).hasClass('in') == false){ $(this).hide(); }; }); } }); })(jQuery); $(window).resize($.adjustModalMaxHeightAndPosition).trigger("resize");
Javascript:
(function($) { $('.modal-trigger').click(function(e){ e.preventDefault(); var href = $(this).attr('href'); var target = $(this).data('target'); $('.' + target + ' .modal-content').load(href, function(result){ $('.' + target).modal({show:true}); $('.' + target).on('loaded.bs.modal', $.adjustModalMaxHeightAndPosition()); }); }); $('.modal').on('click', 'a', function (e) { e.preventDefault(); var href = $(this).attr('href'); var target = $(this).data('target'); $('.' + target + ' .modal-content').html('').load(href, function(result){ $('.' + target).on('loaded.bs.modal', $.adjustModalMaxHeightAndPosition()); }); }); })(jQuery);
Here http://naturarisponde.it you can see a working example by clicking on "Privacy Policy" and "Cookie Policy" at the bottom of page.
<div class="modal">...</div>) replaced with the linked page? What about resizing the modal after the load? Necessary?