Your issue has multiple layers of complexity, all of which venture into uncharted waters.
In the early days of web browsers, the window.open
function did exactly what its name suggests - it opened a new window. This was before the advent of tabbed browsing. When tabs were introduced, they were essentially treated as windows for compatibility reasons, and this practice continues today. Due to the recent standardization of window.open
, JavaScript struggles to differentiate between tabs and windows.
There is no definitive method to specify if a link should open in a new tab or not. However, there is a workaround: you can set a custom window size when using the window.open
function, like this:
window.open('http://example.com', '', 'width=' + screen.width);
This trick will prompt most browsers to open a separate window because tabs cannot have customized dimensions.
In the realm of JavaScript, there exist two categories of events: trusted and untrusted. Trusted events include authentic user actions like clicking on a link, while untrusted events encompass scenarios such as manual calls to the click()
function.
New windows or tabs can only be opened by trusted event handlers. This safety measure is in place to guard against client-side attacks that could potentially crash the browser or overwhelm the user with an excessive number of tabs triggered by events like mouseover
.
The scenario where your attempted popup fails is due to the popup blocker intercepting the untrusted event initiated by the click()
function. Despite originating from a genuine user click, the interruption caused by the asynchronous call disrupts the thread of trustworthiness.