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);
        });
    });
4

1 回答 1

2

您可以使用 JQuery clone() 方法执行此操作(我使用的 url 是示例 PDF):

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);
        }); });

看到它在这里工作:

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

于 2013-04-18T14:38:21.663 回答