print()在Firefox上不起作用

时间:2013-07-19 02:38:31

标签: firefox printing

我已经制作了一个代码,用于从我的网站上打印一些图像。 身体就像这样

<body>
  <img src="http://localhost/upload/qrsample.png" id="barcode">
  <a>
  <img src="http://localhost/upload/icon_printer.png" onclick="javascript:printImg()">
  </a>
</body>

和javascript这样的功能

<script type="text/javascript">
  function printImg() {
    pwin = window.open(document.getElementById("barcode").src);
    pwin.print();
  }
</script>

它在Chrome上运行良好,但在Firefox上无效。但我的网站应该在Firefox上运行,那么有谁可以帮我解决这个问题? 我应该更改浏览器或代码吗?

1 个答案:

答案 0 :(得分:1)

没有适用于Window对象的公共标准,但所有主流浏览器都支持它。

function printImg() {

ImageLink=document.getElementById("barcode").src;
pwin=window.open('','','width=200,height=100');
pwin.document.write("<img src='" + ImageLink + "'/>");
pwin.print();

}

我认为这样可以解决问题。或者你可能设置了弹出窗口阻止程序,因为这会创建一个可能失败的新窗口,