1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Open new tab in background with javascript angular

Discussão em 'Angular' iniciado por Alfareza Mahendra, Outubro 26, 2024 às 04:52.

  1. iam trying to open in new tab in background with angular, already browsing about this but it seems still doesn't works.

    please see the function below :

    openProductInNewTab(productId: number) {
    const url = this.router.serializeUrl(this.router.createUrlTree(['/product', 'detail', productId]));

    // Buka tab baru
    const newWindow = window.open(url, '_blank', 'noopener,noreferrer');

    setTimeout(() => {

    if (newWindow) {
    window.focus(); // Kembali ke tab utama
    }
    }, 500);
    }


    here i attached the html code :

    <td style="width: 27%; padding-left: 20px" nowrap *ngIf="this.ls.selectedLanguages == 'id'">
    <strong (click)="openProductInNewTab(item.id)" class="text-blue">
    {{ item.name }}
    </strong>
    </td>


    so the problem is, my browser (edge) is always open the new tab directly and never go back to the main tab. I want to stay focus on main tab and just open the new tab in background tab for the ideal solution. Do you have any alternative solution about this ? Thank you because iam getting stuck.

    i have already trying iframe, put the url on variable a, add the windows.blur() but none of these ever work on my local instead.

    Continue reading...

Compartilhe esta Página