簡體   English   中英

圖像未出現在打印預覽鑲邊

[英]Image is not appearing in the print preview chrome

雖然我們要打印 HTML 頁面,但圖像沒有出現在打印預覽中,但我嘗試了多個區域但沒有生成輸出。 現在在打印預覽中它沒有顯示正確的。 非常要求大家,請幫助解決這個問題。

輸入:

<?xml version="1.0" encoding="UTF-8"?>
<pat id="Main_Window">
    <title>Main Window</title>
    <body>
        <p>The main console screen includes nine panels or areas, which are shown and described below.</p>
        <p><image width="600" href="../MiVBC_Graphics1/MainWindow_CloudlinkChat.bmp" placement="break"/></p>
        <p>Content here</p>
        <p>Content here</p>
        <p>Content here</p>
        <p>Content here</p>
    </body>
</pat>

Java腳本代碼:

function printIframe(url, height) {
                var heading_one = window.iframeHeight.heading
                var test = window.iframeHeight.maindivcontent
                console.log(test)
                console.log("fhghfjghdfjghfdg")
                var proxyIframe = document.createElement('iframe');
                var body = document.getElementsByTagName('body')[0];
                body.appendChild(proxyIframe);
                proxyIframe.style.width = '100%';
                proxyIframe.style.height = '100%';
                proxyIframe.style.display = 'none';
                var contentWindow = proxyIframe.contentWindow;
                contentWindow.document.open();
                var is_chrome = Boolean(contentWindow.chrome);
                contentWindow.document.write(test)
                contentWindow.document.write('<iframe onload="print();" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
                contentWindow.document.close(); 
                if (is_chrome) {
                    contentWindow.onload = function() { 
                    };
                }
                else {contentWindow.document.write('<iframe onload="print();" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
    contentWindow.document.close(); }return true;}

在打印模式之外它是否仍然顯示給您? 因為當我測試你的代碼時它沒有。 但是,當您將img href更改為src時,它會起作用:

<p><image width="600" src="../MiVBC_Graphics1/MainWindow_CloudlinkChat.bmp" placement="break"/></p>

您需要設置一個超時來給瀏覽器一些時間來呈現圖像。 嘗試這個:

setTimeout(function() {
    contentWindow.print();
    contentWindow.close();
}, 250);

而且您還需要使用 src 而不是 href

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM