【问题标题】:printing a pdf opened in iframe sourced by google doc viewer by javascript通过 javascript 打印在 iframe 中打开的 pdf,该 pdf 由 google doc viewer 提供
【发布时间】:2014-02-09 11:11:53
【问题描述】:

是否可以通过 javascript 打印在 iframe 中打开的 pdf 文件,该文件由 google doc viewer 提供...?出于某种原因,我希望用户在同一页面上并从同一页面打印 pdf...

这是 iframe 的代码:

<button style="height:35px; cursor:pointer; " class="button" id="print"> <img src="images/print.png"/> <span style=" vertical-align: super; "> Print this note </span> </button>   
<?php echo '<iframe id="PDFtoPrint" src="http://docs.google.com/gview?url='.JURI::root().'resources/pdf_full/'.$full_name.'&embedded=true" style="width:800px; height:1000px; " frameborder="0"></iframe>';?>

这是打印出来的 jquery 代码...

 jQuery(document).ready(function($) {

    $('#print').click(function(){
        // window.frames["PDFtoPrint"].focus();
        // window.frames["PDFtoPrint"].print();    // NOT WORKING

        // var PDF = document.getElementById('PDFtoPrint');
        // PDF.focus();
        // PDF.contentWindow.print();              // NOT WORKING

        // $("#PDFtoPrint").get(0).contentWindow.print();  // NOT WORKING

        // document.getElementById("PDFtoPrint").contentWindow.print(); // NOT WORKING


    });
 });

【问题讨论】:

    标签: javascript pdf iframe printing google-document-viewer


    【解决方案1】:

    不,由于 JavaScript 的同源政策,这是不可能的。 JavaScript 无法操作或以其他方式与从另一个域加载到框架中的页面的 DOM 交互。据我所知,有一个例外,但这需要谷歌明确允许您的网站这样做,而他们不会这样做。您可以在此处阅读有关同源政策的更多信息:https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-14
      • 2016-11-04
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多