【问题标题】:Open print window in the same tab without changing the content of the current tab在不改变当前选项卡内容的情况下,在同一个选项卡中打开打印窗口
【发布时间】:2022-11-22 01:17:50
【问题描述】:

我在单击打开打印窗口的按钮时调用此函数,但我的页面内容也更改为 htmlData。我不想更改我的页面内容,而只想更改打开的打印窗口的内容。

任何解决方案?谢谢。

 print() {

   const WinPrint = window.open(
          " ",
          "_self",
          "left=0,top=0,width=900,height=900,toolbar=0,scrollbars=0,status=0"
        );
    
    let htmlData =
          "<html><head> <style....</html>";
        WinPrint.document.write(htmlData);
        WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
}

【问题讨论】:

标签: javascript html jquery dom


【解决方案1】:

您将窗口上下文设置为 "_self"。自身以当前窗口为目标。

您需要 "_blank" 或任何其他不是指向同一窗口的 target 的名称。

【讨论】:

    猜你喜欢
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多