Open & Close Tabs in browser

0 Answers 1120 Views
Button Security Window
Peter
Top achievements
Rank 1
Iron
Iron
Peter asked on 14 Apr 2022, 10:30 AM | edited on 14 Apr 2022, 11:54 AM

Hi, I'd like to close all tabs, which were opened by user.

I have problem, it still closes only one opened tab. I use this methods:

 <TelerikButton OnClick="@OpenTabC" Primary="true">Open Tab C</TelerikButton>
<TelerikButton OnClick="@OpenTabF" Primary="true">Open Tab F</TelerikButton>
<TelerikButton OnClick="@CloseTabs" Primary="true">Close Tab</TelerikButton>

 

async Task OpenTabC()
    {
        await JS.InvokeVoidAsync("open", $"counter", "_blank");        
    }

    async Task OpenTabF()
    {
        await JS.InvokeVoidAsync("open", $"fetchdata", "_blank");
    }

    async Task CloseTabs()
    {        
        var loadDataTasks = new Task[]
        {
            Task.Run(async () =>  await JS.InvokeVoidAsync("close", $"counter")),
            Task.Run(async () =>  await JS.InvokeVoidAsync("close", $"fetchdata"))
        };

        try
        {
            Task.WaitAll(loadDataTasks);
        }
        catch (Exception ex)
        {
            // handle exception
        }        

  }

What is wrong in CloseTabs method, please, why does it close only one tab?

It is possible to do without JS.InvokeVoidAsync?

Thank you

Peter

Dimo
Telerik team
commented on 19 Apr 2022, 08:23 AM

Peter - check this StackOverflow thread and experiment with a similar approach. You will need JavaScript by all means.

This question is related to general programming, so I am removing our component-related tags.

No answers yet. Maybe you can help?

Tags
Button Security Window
Asked by
Peter
Top achievements
Rank 1
Iron
Iron
Share this question
or