javascript - How do I load my pdf file into my modal when the button is clicked? -


i have button that, when clicked, opens modal pdf content. have list of these.

my problem when browser loads website loads pdf files. want specific pdf file load when press button opens 1 specific modal.

<li>      <div class="row">         <div class="col-md-2" style="border: 1px solid black; height:200px;">             <img src="images/immanuelkant.jpg" style="padding:5px;" height="198" width="150">          </div>         <div class="col-md-8">             <div class="row">                 <div class="col-md-6">                     <h2>immanuel kant</h2>                     <h3>something</h3>                     <p>                      </p>                       <!-- modal -->                     <div style="display: block;" class="modal modal-wide fade in" id="läsmodal8" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="false">                         <div class="modal-dialog">                             <div class=" modal-content">                                  <div class="modal-body">                                    <iframe class="pdfcontainer" src="viewerjs/../books/somepdf.pdf" allowfullscreen="" webkitallowfullscreen="" height="700px" width="100%"></iframe>                                  </div>                                 <div class="modal-footer">                                     <button type="button" class="btn btn-default" data-dismiss="modal">close</button>                                  </div>                             </div>                         </div>                     </div>                 </div>                 <br>                 <div class="col-md-6">                          sometext                       <a href="http://en.wikipedia.org/wiki/immanuel_kant" target="_blank">read about</a>                  </div>             </div>             <hr>             <form>             <div class="row">                 <div class="col-md-2">                     <button type="button" class="btn btn-default btn-lg" data-toggle="modal" data-target="#läsmodal8">                         read                     </button>                  </div>                 <div class="col-md-6">              </div>             </form>         </div>      </div>     <br>     <hr style="border-color:rgba(0, 0, 0, .3);">     <br> </li> 

change src attribute of iframe in modal. urls of pdf files can stored in custom attribute of buttons, , if have iframe in element (jquery or simple javascript), can set attributes src too. js maybe it's myiframe.setattribute('src','http://...'), or jquery this: myiframe.attr('src','http://...'). best solution think, if set pdf url each button mentioned above, , if can use jquery, add piece of code page this:

jquery('.modalbutton').click(function(){   var pdf = jquery(this).attr('data-pdfurl');   jquery('iframe #modal').attr('src', pdf); }); 

(this "skeleton", might not work correctly...)


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -