title: whmcs invoice in new tab
body: <p>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.</p>
  
  <p>This is the js</p>
  
  <pre><code>            &lt;script&gt;
              function OpenInNewTab(url) {
                  var win = window.open(url, '_blank');
                  win.focus();
                   }
              &lt;/script&gt;
  </code></pre>
  
  <p>this is the code to call the invoices and display it in a table. note: this is a smarty .tpl</p>
  
  <pre><code>&lt;tr onclick="clickableSafeRedirect(event, OpenInNewTab('viewinvoice.php?id={$invoice.id}'), false)"&gt;
                      &lt;td&gt;{$invoice.invoicenum}&lt;/td&gt;
                      &lt;td&gt;&lt;span class="hidden"&gt;{$invoice.normalisedDateCreated}&lt;/span&gt;{$invoice.datecreated}&lt;/td&gt;
                      &lt;td&gt;&lt;span class="hidden"&gt;{$invoice.normalisedDateDue}&lt;/span&gt;{$invoice.datedue}&lt;/td&gt;
                      &lt;td&gt;{$invoice.total}&lt;/td&gt;
                      &lt;td&gt;&lt;span class="label status status-{$invoice.statusClass}"&gt;{$invoice.status}&lt;/span&gt;&lt;/td&gt;
                      &lt;td class="responsive-edit-button" style="display: none;" &gt;
                          &lt;a href="viewinvoice.php?id={$invoice.id}" class="btn btn-block btn-info" &gt;
                              {$LANG.manageproduct}
                          &lt;/a&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  </code></pre>
  
  <p>I added the OpenInNewTab in this line</p>
  
  <pre><code>&lt;tr onclick="clickableSafeRedirect(event, OpenInNewTab('viewinvoice.php?id={$invoice.id}'), false)"&gt;
  </code></pre>
  
  <p>and this was the original code</p>
  
  <pre><code>&lt;tr onclick="clickableSafeRedirect(event, viewinvoice.php?id={$invoice.id}, false)"&gt;
  </code></pre>
  
  <p>Thanks in advance!!</p>
  
  <p>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.</p>
  
  <p>This is the clickableSafeRedirect function</p>
  
  <pre><code>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' &amp;&amp; eventSource != 'a') {
          if(eventParent != 'button' &amp;&amp; eventParent != 'a') {
              if (newWindow) {
                  window.open(target);
  
              } else {
                  window.location.href = target;
  
              }
          }
      }
  }
  </code></pre>