window.open API returns null although the browser is launched.

Qi Yang 0 Reputation points Microsoft Employee
2025-01-22T03:04:31.4066667+00:00

I'm trying to check the result of "window.open" API. This is my code:

const result = window.open(link, "_blank");
if (!result) {
   throw new Error ("Failed to open the link window");
}

It works well when the code runs in the browser. Most of time, window.open will return the object. It returns null when there is a pop-up blocker.
But when it runs in the WebView of Window Desktop, it would always return null although launch the browser tab successfully.

I have two questions:
Firstly, I want to confirm is this some similar bug in Edge like https://bugzilla.mozilla.org/show_bug.cgi?id=1466347#c4.

Secondly, is there any other way that I could check whether the browser have been opened?

Any solution or suggestions would be appreciated! Thanks!

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,464 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.