The standard popup-blocker logic contained in most browsers these days will block any calls to window.open() that are not the direct result of a user action. Code that is triggered by timers or by any asynchronous callback (like your ajax ready function) will be treated as NOT caused directly by user actions and the new popup window will generally be blocked.

You can verify this is what is happening by temporarily changing your browser's popup blocking (turning it off) and see that it then starts working.

Probably what you need to do as a work-around is to create the window upon the user action that started this thread of code and then put the content into the window when you get your ajax response. The browser will probably allow that. I know that's less desirable from a visual perspective, but you can put some temporary content in the window until the ajax response comes in (something like "loading...").

Answer from jfriend00 on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN
This feature is not Baseline because it does not work in some of the most widely-used browsers. * Some parts of this feature may have varying levels of support. ... The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.
Discussions

window.open not opening window
I'm trying to open a page in a popup as opposed to new tab - but whichever browser I try this simply opens in a new tab, not popup. More on stackoverflow.com
🌐 stackoverflow.com
Javascript Window Open not working
Hi guys, I’m using self-hosted 2.0 version. A few days ago I’ve made a button column and attached to a script that takes a url string and call window.open(url). It was working during my tests, but now I’m getting error: TypeError: Cannot read property ‘open’ of undefined at Proxy.main ... More on forum.seatable.com
🌐 forum.seatable.com
1
0
June 15, 2021
Window.open(); doesn't work properly | Vivaldi Forum
Why doesn't this or that work yet? Because it is still an alpha and under heavy development. Firefox has an option "Open new windows in a tab instead" - are you saying that is the wrong thing to do? If users want to open windows across several monitors I'm sure they will (eventually) be able to do so, though I'm sure many users will choose not ... More on forum.vivaldi.net
🌐 forum.vivaldi.net
March 7, 2015
Javascript window.open not working
Find answers to Javascript window.open not working from the expert community at Experts Exchange More on experts-exchange.com
🌐 experts-exchange.com
January 27, 2008
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Window.open not working for me
August 7, 2018 - I am trying to render a new webpage per value of the input type number but I have not gotten it. HTML JAVASCRIPT/JQUERY $("#start").click(function(){ if($("#year").val()===2018) { window.open(...
🌐
SeaTable Forum
forum.seatable.com › user talk
Javascript Window Open not working - User Talk - SeaTable Forum
June 15, 2021 - Hi guys, I’m using self-hosted 2.0 version. A few days ago I’ve made a button column and attached to a script that takes a url string and call window.open(url). It was working during my tests, but now I’m getting error: TypeError: Cannot read property ‘open’ of undefined at Proxy.main ...
🌐
Microsoft Community Hub
techcommunity.microsoft.com › microsoft community hub › communities › products › microsoft edge insider › enterprise
Window.open not working | Microsoft Community Hub
Since my application is an enterprise and we used to open window which is popup window using window.open() method. After this upgrade we are not able to open any popup window. Our application is purely rely on window.open() feature.
🌐
Vivaldi
forum.vivaldi.net › topic › 1552 › window-open-doesn-t-work-properly
Window.open(); doesn't work properly | Vivaldi Forum
March 7, 2015 - Large HTML overlay injections are messy, hard to maintain, not modular, and perform poorly. Also because they are fake HTML overlays, rather than new window instances, the popup content must be contained within the parent's working space thus you could never have a small window open an entry form that requires a larger space.
Find elsewhere
🌐
Experts Exchange
experts-exchange.com › questions › 23248607 › Javascript-window-open-not-working.html
Solved: Javascript window.open not working | Experts Exchange
January 27, 2008 - I put the full path and it still didn't work. I even test the path in the browser to make sure it was fine. I noticed the form seems to be postingback on it's self. The bottom of the page is show the url for the current page it's on. Thanks ... On the client side: I have checked to make sure the 'pop up blocker' are off. Internet security is set to meduim Not sure what else could be causing the window.open feature not to work.
🌐
SitePoint
sitepoint.com › javascript
Having trouble with window.open and _self
October 7, 2008 - if I do this: window.open(url_var,‘_self’); it works in IE but not in FF or chrome. but this: window.open(url_var); works in all 3 but opens a new window…I want to stay in the same window. Can I get a clue? THanks…
🌐
Medium
ffan0811.medium.com › window-open-returns-null-in-safari-and-firefox-after-allowing-pop-up-on-the-browser-4e4e45e7d926
window.open returns null in Safari and Firefox after allowing pop-up on the browser | by Mijeong | Medium
December 12, 2021 - const onClick = async () => { const { popupUrl } = await requestPopupUrl(); const popup = window.open(popupUrl); setInterval(() => { console.log(popup); // returns null every one second }, 1000); }; ... Even if you make a direct interaction like clicking a button, timers or any asynchronous callback will be treated as not a direct interaction and the pop-up window will be blocked. I changed the code to the code below and now everything works.
🌐
Reddit
reddit.com › r/learnjavascript › javascript windows.open not working!
r/learnjavascript on Reddit: Javascript windows.open not working!
August 10, 2021 -

I have set a password on my site and im trying to get it working completly. i have the whole login system but it is writen in an javascript. but i got one problem. if the password is guessed correct it should open my main.html. but it won't open.

This is my code

window.open('main.html',"_self");

it wont open the main html if the target is _self. it will open when there is no target. it also will open https://www.google.com/ if i use :

windows.open( 'https://www.google.com/','_self');

Can anyone help me?

🌐
W3Schools
w3schools.com › jsref › met_win_open.asp
Window open() Method
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
🌐
Google Groups
groups.google.com › g › google-web-toolkit › c › I40UtQ2IukU
Window.open not working on Chrome 5 ( GWT 2.0.4 )
This means that you cannot open a window in a callback. That is asynchronous that is not a direct result of a user action.
🌐
Reddit
reddit.com › r/learnjavascript › my browser is blocking my userscript's window.open()
r/learnjavascript on Reddit: My browser is blocking my userscript's window.open()
May 31, 2023 -

I am trying to create a temporary fix for this highly-annoying bug:

https://www.reddit.com/r/help/comments/13o7yif/why_does_reddit_open_image_links_in_their/

The solution to bust the proprietary image viewer is to open the image URL in a new tab and then close the current tab:

//Check to see if the image is being loaded in Reddit's proprietary image viewer. If the element exists, open the URL in a new tab and then close the current.
let elImg = document.querySelector("img.object-contain");
if (elImg) {
    window.open(elImg.src,"_blank");
    window.close();
}

This works great when executed in the dev console directly, but Brave blocks it as a pop-up when it's executed by my Tampermonkey userscript. Is there a way to somehow trust the userscript source? Or perhaps there is another way to open a URL in a new tab without being blocked?

Update: While not an ideal solution, this does work:

let elImg = document.querySelector("img.object-contain");
if (elImg) {
    elImg.addEventListener("click", function() {
        window.open(this.src,"_blank");
        window.close();        
    });
}

It turns out that pop-ups are blocked when not executed by a user action. If I invoke the code by adding a click event to the element, it will work. However, I am still looking for a way to execute the code when the page loads.

🌐
PlayCanvas
forum.playcanvas.com › help & support
[SOLVED] Window.open() doesn't work in Safari in iPhone - Help & Support - PlayCanvas Discussion
September 23, 2022 - window.open() doesn’t work in safari in iPhone. “Doesn’t work” means it does not open a window when it is called. Nothing happens. It works in Safari in iPad. It works in Safari in desktop. It works in chrome in anyw…
🌐
Microsoft Learn
learn.microsoft.com › th-TH › troubleshoot › browsers › value-of-windowopen-not-reflected
Call window open() function - Browsers | Microsoft Learn
Describes an issue in which a window that is opened by the window.open() function don't reflect the specified size and position in Microsoft Edge.
🌐
Airtable Community
community.airtable.com › home › ask the community › other questions › javascript window.open()
Javascript window.open() | Airtable Community
January 14, 2021 - I realized i should try the different window.open() target attribute. So changing to “_blank” almost worked in that the custom app made the record. But would still get an error, but a new error that said something to the effect if not rendering anything, then should return null.