Is there a way to generate a preview of PDF in IE

假如想象 提交于 2019-12-08 12:59:50

问题


Is there anyway at all to generate a preview of a PDF in an IE browser?

I know that you could use an iframe in either Chrome or Firefox, and a blob in IE, but they both require their own code, I'm looking for something that will work cross browsers.


回答1:


Finally found a solution, that generates an in-browser preview window for a PDF file that is supported by all browsers!

Here's my code (I've put in an input box so that anyone could test any PDF URL):

<div class="wizard-content">
     <div class="col-md-6">
          <input id="pdfsrc" class="form-control">
          <a id="refresh" href="#" class="btn btn-lg btn-success">Refresh PDF</a>
     </div>
     <div id="myDiv" class="col-md-6">
          <object id="objsrc" data="" type="application/pdf" style="width:100%;height:100%">
              <embed id="embsrc" src="" type="application/pdf" style="width:100%;height:100%/">
          </object>
     </div>
</div>

JS:

$(function() {
    $("#refresh").click(function() {
        var url=document.getElementById('pdfsrc').value;
        $("#objsrc").attr("data", url);
        $("#embsrc").attr("src", url);
        var container = document.getElementById("myDiv");
        var content = container.innerHTML;
        container.innerHTML = content;
    })
})


来源:https://stackoverflow.com/questions/36461321/is-there-a-way-to-generate-a-preview-of-pdf-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!