{"id":6325,"date":"2017-01-23T11:02:06","date_gmt":"2017-01-23T16:02:06","guid":{"rendered":"https:\/\/www.caskeys.com\/dc\/?p=6325"},"modified":"2026-05-18T17:41:39","modified_gmt":"2026-05-18T21:41:39","slug":"bootstrap-remote-file-models","status":"publish","type":"post","link":"https:\/\/www.caskeys.com\/dc\/bootstrap-remote-file-models\/","title":{"rendered":"Bootstrap Remote File Modals"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-fad1e6427cf7e421fa917a4c2523bce2 wp-block-paragraph\"><strong>Notice:<\/strong> Bootstrap\u2019s built-in remote modal loading was deprecated in Bootstrap 3.3.0 and removed in Bootstrap 4. This article applies to legacy Bootstrap 3 projects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Opening a modal is <a href=\"http:\/\/www.w3schools.com\/bootstrap\/bootstrap_ref_js_modal.asp\">well documented<\/a> for the Bootstrap framework when the modal\u2019s contents are located within the same document. However, if the modal content is stored in a remote file, the process becomes slightly more nebulous. After some experimenting and Stack Overflow research, I compiled the following steps.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Link<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The link for opening a modal must still target a container element of some sort, typically a DIV id. You may also choose to target the container by class. For remote files, you need to include an href attribute as well, targeting the remote file location.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: Code:; notranslate\" title=\"Code:\">\n&lt;a href=&quot;modal_document.php&quot; data-target=&quot;#modal_div_container_id&quot; data-toggle=&quot;modal&quot;&gt;Open Modal&lt;\/a&gt;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Modal Container<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next you need to prepare the calling document (the same document that contains the modal link) with a modal container. This is exactly the same as with a normal modal, except you are only adding the modal&#8217;s <em>container elements<\/em>, not its <em>content<\/em>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: Code:; notranslate\" title=\"Code:\">\n&lt;div class=&quot;modal fade&quot; id=&quot;modal_div_container_id&quot;&gt;\n    &lt;div class=&quot;modal-dialog&quot;&gt;\n        &lt;div class=&quot;modal-content&quot;&gt;\n            &lt;!-- Modal content area - leave this empty.--&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Modal Document (Content)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The last step is to prepare your remote document. Add whatever content you wish. The only special caveat to consider is you do NOT add the modal container elements to this document. You only add the content. The content itself may include its own container elements, formatting, and so forth. In the example below, the modal is a simple list, and therefore only the markup for the list is included.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: Code:; notranslate\" title=\"Code:\">\n&lt;ul&gt;  \n    &lt;li&gt;Item 1&lt;\/li&gt;\n    &lt;li&gt;Item 2&lt;\/li&gt;\n    &lt;li&gt;Item 3&lt;\/li&gt;\n&lt;\/ul&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ve probably already guessed what&#8217;s going on here. When the modal link is clicked, Bootstrap loads the remote document\u2019s contents and injects them into the .modal-content element inside the targeted modal container. <a href=\"http:\/\/getbootstrap.com\/javascript\/#modals\" target=\"_blank\" rel=\"noopener\">Bootstrap Modal Documentation<\/a> (extracted 2017-01-23):<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">If a remote URL is provided, <strong>content will be loaded one time<\/strong> via jQuery&#8217;s <code>load<\/code> method and injected into the <code>.modal-content<\/code> div. If you&#8217;re using the data-api, you may alternatively use the <code>href<\/code> attribute to specify the remote source.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">This is why you must include a target element in the calling document, and conversely NOT include modal containers in the remote document. Hope this helps. Special thanks to <a href=\"http:\/\/stackoverflow.com\/users\/3358027\/buzinas\" target=\"_blank\" rel=\"noopener\">Buzinas<\/a> from Stack Overflow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Until next time!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DC<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Bootstrap&#8217;s modal dialog to open remote files.<\/p>\n","protected":false},"author":1,"featured_media":6316,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Using Bootstrap's model dialog to open remote files. #technology_temerity","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[71],"tags":[312,27,269,234,298,238],"class_list":["post-6325","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology-temerity","tag-coding-bootstrap","tag-coding","tag-applications-inspector-blair","tag-coding-php","tag-technology-temerity","tag-coding-web-development"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.caskeys.com\/dc\/wp-content\/uploads\/2017\/01\/logo-bootstrap-e1485266840776.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5lNM5-1E1","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/posts\/6325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/comments?post=6325"}],"version-history":[{"count":8,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/posts\/6325\/revisions"}],"predecessor-version":[{"id":7916,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/posts\/6325\/revisions\/7916"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/media\/6316"}],"wp:attachment":[{"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/media?parent=6325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/categories?post=6325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.caskeys.com\/dc\/wp-json\/wp\/v2\/tags?post=6325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}