如果内容数据是base64,则window.parent.xxx.print()不起作用

时间:2017-09-13 05:47:52

标签: javascript jquery pdf iframe

我有一个iframe,我动态生成一个base64数据pdf文件:

$("#pdfDocument").attr('src', "data:application/pdf;base64,"+base64data);

表单上有一个按钮,点击后它应该调用浏览器的默认print行为:

<button type="button" onclick="window.parent.pdfDocument.print();" style="width:13em;margin-right:10px;"  class="btn btn-primary btn-sm" >$i18n.getString( "btn_form_print" )</button>

pdfDocument这里是iframe的名称:

<iframe style="border: 0 none" src="" id="pdfDocument" name="pdfDocument" width="100%" height="550" type='application/pdf'> </iframe>

当我点击此按钮时,我收到以下错误:

  

未捕获的DOMException:阻止了一个包含起源的框架&#34; http://localhost:8080&#34;从访问跨源框架。       在HTMLButtonElement.onclick

但是,当我直接将pdf文件作为iframe中的源文件时,它可以正常工作。仅当我将pdf文件作为base64数据输入时,它才会出错。

欢迎任何想法或指示。

0 个答案:

没有答案