2

I am creating an HTML front page for users to view our 'How To' documents, the pdfs are fembeded onto the page to create a preview using the below JQuery. This is working fine in Firefox however will not work in IE or Chrome, any help is appreciated, Thanks

    $(document).ready(function() {
        "use strict";
        $('.btn').click(function() {
            var idToSRC = './HTA_' + this.id + '.pdf';
            $('#viewer').attr('src', idToSRC);
        });
    });
Wez
  • 10,555
  • 5
  • 49
  • 63

1 Answers1

2

You can do this using the JQuery clone() method (the urls I used are example PDFs):

http://api.jquery.com/clone/

<button type="button" class="btn">Change Src</button>
<div>
    <embed id="viewer" src="http://www.education.gov.yk.ca/pdf/pdf-test.pdf" width="500" height="680"></embed>
</div>

 $(document).ready(function() {
        "use strict";
        $('.btn').click(function() {
            //var idToSRC = './HTA_' + this.id + '.pdf';
            var idToSRC = "http://www.reservoirminerals.com/files/doc_downloads/test.pdf";
            var $viewerDiv = $('#viewer').parent();          
            var viewerClone = $('#viewer').clone().attr('src', idToSRC);
            $viewerDiv.html(viewerClone);
        }); });

See it working here:

http://jsfiddle.net/W32RA/2/

MasNotsram
  • 2,105
  • 18
  • 28