0

在下载后的以下代码中,我想通过 jquery/javascript 打印下载的文件。

但无法确定我需要将打印命令放在哪里以及需要如何处理。任何帮助将不胜感激 - 谢谢

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("a").click(function(e) {
        $('a#test').attr({target: '_blank', 
                href  : 'http://localhost/text.txt'});
    });
    var downloadURL = function downloadURL(url) {
        var hiddenIFrameID = 'hiddenDownloader',
            iframe = document.getElementById(hiddenIFrameID);
        if (iframe === null) {
            iframe = document.createElement('iframe');
            iframe.id = hiddenIFrameID;
            iframe.style.display = 'none';
            document.body.appendChild(iframe);
        }
        iframe.src = url;
    };
});
</script>
<body>
<a id="test" href="#">Download now!</a>
</body>
</html>
</head>
4

1 回答 1

0

要打印 iframe 的内容,只需使用:

iframe.contentWindow.print();
于 2013-08-21T07:28:42.407 回答