jquery 使用iframe打印文件流
时间: 2023-07-06 14:09:19 浏览: 61
可以使用以下代码使用 jQuery 和 iframe 打印文件流:
```javascript
function printStream(stream) {
var iframe = $("<iframe/>").css({
position: "absolute",
width: "0px",
height: "0px",
left: "-500px",
top: "-500px"
}).appendTo("body")[0];
var iframeDoc = iframe.contentWindow ? iframe.contentWindow : (iframe.contentDocument.document ? iframe.contentDocument.document : iframe.contentDocument);
iframeDoc.document.open();
iframeDoc.document.write("<html><head></head><body><iframe src='" + stream + "'></iframe></body></html>");
iframeDoc.document.close();
setTimeout(function () {
iframe.contentWindow.focus();
iframe.contentWindow.print();
$(iframe).remove();
}, 500);
}
```
其中,`stream` 是文件流的 URL。该函数会创建一个隐藏的 iframe,并将文件流的 URL 嵌入其中,然后调用 iframe 的 `print()` 方法打印页面。