在边缘浏览器中打印时默认设置页眉和页脚是打开还是关闭?

时间:2018-05-02 05:13:07

标签: javascript css printing microsoft-edge

我已经搜索了很多但是在Edge浏览器中默认情况下没有找到任何方法在每个打印页面上启用页眉和页脚。

在Chrome和IE页眉和页脚上默认显示,但在Edge中默认为OFF。是否需要为Edge浏览器设置任何CSS属性,以便在每个打印页面上默认显示页眉和页脚?

以下是用于打印页面的JS和CSS:

private createIframe() {
        let oldFrame: any = document.getElementsByClassName('e-ngx-print-frame');
        if (oldFrame.length > 0) {
            oldFrame[0].parentNode.removeChild(oldFrame[0]);
        }
        try {
            let printIframe: any = document.createElement('iframe');
            document.body.appendChild(printIframe);
            printIframe.style.position = 'absolute';
            printIframe.style.border = '0';
            printIframe.style.width = '0';
            printIframe.style.height = '0';
            printIframe.style.left = '0';
            printIframe.style.top = '0';
            printIframe.style.zIndex = '-1';
            printIframe.className = 'e-ngx-print-frame';
            this.printWindow = printIframe.contentWindow;
            this.printDoc = printIframe.contentDocument ? printIframe.contentDocument : (printIframe.contentWindow ? printIframe.contentWindow.document : printIframe.document);
        }
        catch (e) {
            throw e + '. iframes may not be supported in this browser.';
        }

        if (!this.printWindow) {
            throw 'Cannot find window.';
        }

        if (!this.printDoc) {
            throw 'Cannot find document.';
        }
    }

    private getPrintWindow() {
        if (this.mode === this.modes.iframe) {
            this.createIframe();
        } else if (this.mode === this.modes.popup) {
            this.createPopup();
        }
    }

public print(printHTML?: any) {
        this.printHTML = printHTML ? printHTML : this.printHTML;
this.oldBtnText = this.btnText;
        this.btnText = 'Print';
        let timeoutId: number = window.setTimeout(() => {
            window.clearTimeout(timeoutId);
            this.getPrintWindow();
            this.write();
            this.startPrint();
        }, 500);
    }

**CSS**:
 @media print 
    {
@page 
      {
        size: auto;   /* auto is the initial value */
       margin-top:0mm; /* this affects the margin in the printer settings */
      }
}

0 个答案:

没有答案