javascript – Opening link in new tab from Blazor Server


I’m trying to open a link in a new tab from a Blazor Server application. I tried several methods such as

await JSRuntime.InvokeVoidAsync("open", action.ActionData, "_blank");

as well as

await JSRuntime.InvokeVoidAsync("NavigateTo", action.ActionData);

whereas the NavigateTo function appears as follows:

window.NavigateTo = (url) => {
    const link = document.createElement('a');
    link.href = url;
    link.target="_blank";
    document.body.appendChild(link);
    link.click();
    link.remove();
}

Everything is working fine in all browsers except for Safari on IOS.

Has anybody found a solution to this problem? As I found out, there is a problem opening a new tab in Safari from an asynchronous task. But I couldn’t find a way to start this synchronously from Blazor Server.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img