You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular中打开新标签页打印后原标签页交互失效问题求助

Angular打印新标签页后原标签页失去交互性问题

在Angular构建的项目中出现如下问题:在Chrome和Edge浏览器中,打开新标签页并打印其内容后,关闭该新标签页会导致原标签页部分或完全失去交互性,必须手动刷新才能恢复功能。

复现步骤

  • 在原标签页点击按钮触发打印逻辑,新标签页加载完成后自动执行window.print(),具体代码如下:
print() {
    // Your content
    let content = `
    <html>
      <head>
        <title>Print Page</title>
      </head>
      <body onload="window.print()">
        Content
      </body>
    </html>
    `;

    // Create a Blob from the HTML content
    let blob = new Blob([content], { type: 'text/html' });

    // Create a URL for the Blob
    let url = URL.createObjectURL(blob);

    // Open a new tab with the created URL
    window.open(url, '_blank');

    // Release the URL object after the new tab is opened
    URL.revokeObjectURL(url);
  }
  • 点击关闭按钮关闭新打开的标签页。

预期行为

关闭新标签页后,原标签页的功能应保持正常,所有交互元素不应失效。


内容的提问来源于stack exchange,提问作者Tai Pham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 17:54:54