Can window.location be used to open in a new window?

I’m using this function format to open files:

    function chart1() {
        window.location=("https://location/chart.pdf");
    }

It is replacing the browser window, but I want to open a new browser window. This format made the link unresponsive:

window.location=("https://location/chart.pdf" target="_blank" rel="noopener");

How do I use this function to open a new window?

Hi @WebSteve, this is indeed not valid syntax – you can check the console of your browser dev tools for such errors. Anyhow window.location only allows assignment to the current location; what you might do instead is open() a new window like so:

window.open('https://location/chart.pdf', '_blank', 'noopener')

(Note that most browsers will just open a new tab though, depending on the user preferences.)

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.