How to open PDF in new tab with code

I want to open a PDF in a new tab but not with a button.
I have seen this https://www.wix.com/corvid/forum/community-discussion/how-to-open-a-pdf-in-new-browser-window-making-the-active-browser-window-the-displayed-pdf but I cannot work out how to get it to be triggered just by code.

Something like this in regular Javascript perhaps:

window.open('link');

Did you ever figure this out? I’m at the same point.