简体   繁体   English

用Javascript在当前窗口后面打开一个窗口?

[英]Open a window behind the current window with Javascript?

I know that there is already the same question but none of that answers worked for me. 我知道已经存在相同的问题,但是这些答案对我来说都不起作用。

The problem: 问题:

I have an app in angular for firefox where I open a window to print it. 我有一个用于firefox的angular应用程序,在其中打开一个窗口进行打印。 The problem is that I dont want to print it more than once and also dont want that this view to be visible to the user. 问题是我不想多次打印它,也不希望该视图对用户可见。 So I would like to open this new window behind the main app. 所以我想在主应用程序后面打开这个新窗口。

My code: 我的代码:

    let printContents2, popupWin2;
    printContents2 = document.getElementById('to-print').innerHTML;
    popupWin2 = window.open('', '_blank', 'top=10000,left=10000,height=1px,width=1px');
    popupWin2.document.open();    
    popupWin2.document.write(`
    <html>
    <head></head>      
    <body style='width=350px' onload="window.print();window.close();">${printContents2}</body>
          </html>`
        );
    popupWin2.document.close();

What I have tried: 我尝试过的

popupWin2.blur();

window.focus();

onload="window.print();window.close();"

Thank you in advance. 先感谢您。

If it's kind of intranet app and you can force clients to install plugin you can use addons https://addons.mozilla.org/firefox/addon/seamless-print/ Otherwise it's not possible because of security. 如果是Intranet应用程序,并且您可以强制客户端安装插件,则可以使用插件https://addons.mozilla.org/firefox/addon/seamless-print/否则,由于安全原因是不可能的。 Also you can use java-based solution https://github.com/qzind/tray/wiki/2.0-getting-started It depends on what is preferable in your case. 您也可以使用基于Java的解决方案https://github.com/qzind/tray/wiki/2.0-getting-started这取决于您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM