The page with the address currentUrl.ru open. A tab from the code is opened.

For example:

 window.open('currentUrl.ru', '_blank'); 

When the print in the second tab on the first blocking code execution. But if you open the second tab manually (press the plus sign and enter the address), then the tabs of each other do not block.

Is it possible to break the connection between tabs from code?

Copy-paste function that blocks all page buttons until I close the print window:

 function printThisLayout(layout, styles) { if (!styles) styles = ''; let popupWin = window.open('', '_blank', 'width=800,height=600'); let onload = 'window.opener = null;' + 'alert(window.opener);' + 'window.document.close(); /*necessary for IE >= 10*/' + 'window.focus(); /*necessary for IE >= 10*/' + 'window.print();' + 'window.close();'; popupWin.document.write( '<html>' + '<head>' + '<style>' + styles + '</style>' + '</head>' + '<body>' + layout + '</body>' + '<script>' + onload + '</script>' + '</html>'); } 

In the window that opens, an alert appears with the inscription null, after the alert is closed, the print dialog opens, and the parent tab still hangs.

    1 answer 1

    On the page that opens in another tab, you must break the link with the "parent"

     (function() { window.opener = null; })(); 

    https://tproger.ru/articles/target-blank-the-most-underestimated-vulnerability-ever/

    PS Posted by discussion below

     let popupWin = window.open('', '_blank', 'width=800,height=600'); popupWin.onload = function () { popupWin.opener = null; }; 
    • Already tried to do window.opener = false; null didn't work either) - Keith the Fish
    • A new window is already loaded when you add content. Therefore, onLoad in your case does not seem to work - Dmitry Kozlov
    • Fulfills, because the window of the print opens - Fish Kit
    • It is necessary not to add in the text <script> </ script>, but immediately. Added in reply - Dmitry Kozlov
    • I tried both the way you suggested and add to the script. It does not work. Even if at the time window.print () is executed, the link to the opener is broken, the parent is still blocked. ((((((( - Fish Whale