whmcs新标签中的发票

I want to open the invoices of whmcs in a new tab or a popup window. The biggest part of this problem is solved but one thing remains a problem. I used some js to open up the invoice in a new tab, but on the original page, after opening the invoice, it also loads and returns a 404. The invoice opens without any problems.

This is the js

            <script>
            function OpenInNewTab(url) {
                var win = window.open(url, '_blank');
                win.focus();
                 }
            </script>

this is the code to call the invoices and display it in a table. note: this is a smarty .tpl

<tr onclick="clickableSafeRedirect(event, OpenInNewTab('viewinvoice.php?id={$invoice.id}'), false)">
                    <td>{$invoice.invoicenum}</td>
                    <td><span class="hidden">{$invoice.normalisedDateCreated}</span>{$invoice.datecreated}</td>
                    <td><span class="hidden">{$invoice.normalisedDateDue}</span>{$invoice.datedue}</td>
                    <td>{$invoice.total}</td>
                    <td><span class="label status status-{$invoice.statusClass}">{$invoice.status}</span></td>
                    <td class="responsive-edit-button" style="display: none;" >
                        <a href="viewinvoice.php?id={$invoice.id}" class="btn btn-block btn-info" >
                            {$LANG.manageproduct}
                        </a>
                    </td>
                </tr>

I added the OpenInNewTab in this line

<tr onclick="clickableSafeRedirect(event, OpenInNewTab('viewinvoice.php?id={$invoice.id}'), false)">

and this was the original code

<tr onclick="clickableSafeRedirect(event, viewinvoice.php?id={$invoice.id}, false)">

Thanks in advance!!

EDIT: I tried to merge the clickableSafeRedirect function with the OpenInNewTab function, this resulted in an empty tab with the invoice loaded on the original page.

This is the clickableSafeRedirect function

function clickableSafeRedirect(clickEvent, target, newWindow) {

    var eventSource = clickEvent.target.tagName.toLowerCase();
    var eventParent = clickEvent.target.parentNode.tagName.toLowerCase();
    var eventTable = clickEvent.target.parentNode.parentNode.parentNode;
    if (jQuery(eventTable).hasClass('collapsed')) {
        // This is a mobile device sized display, and datatables has triggered folding
        return false;
    }
    if(eventSource != 'button' && eventSource != 'a') {
        if(eventParent != 'button' && eventParent != 'a') {
            if (newWindow) {
                window.open(target);

            } else {
                window.location.href = target;

            }
        }
    }
}

This function clickableSafeRedirect() in WHMCS have a parameter that allows yo to open the new window instead of your custom function.

Remove your OpenInNewTab() function and make this:

clickableSafeRedirect(event, viewinvoice.php?id={$invoice.id}, true);
---------------------------------------------------------------^^^^

Setting true in the third parameter open in new window. Look at the code in whmcs. The definition of the function is:

function clickableSafeRedirect(clickEvent, target, newWindow)