2014-01-20 59 views
1

打印在iframe中打开的pdf是否可以通过javascript文档查看器获取?由于某种原因,我希望用户可以在同一页上,并打印来自同一页面的PDF ...打印在iframe中打开的pdf由google doc查看器通过javascript

这里的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 


    }); 
}); 

回答

1

不,这是不可能的,因为JavaScript的同源策略。 JavaScript无法操纵或以其他方式与另一个域中的帧中加载的页面的DOM进行交互。据我所知,有一个例外,但这将要求Google明确允许您的网站这样做,他们不会这样做。你可以在这里阅读更多关于同源政策:https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy