Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replacing a tab with a different one using JS

Currently, I have something in place that opens a new tab with some html code, using

    const winUrl = URL.createObjectURL(new Blob([final_file], { type: "text/html;charset=utf8" }));
    const win = window.open(winUrl);

where final_file is some html that I generate. I want to make it so instead of opening a new tab every time, if such a tab is already open, it should replace it. I tried using frame names in window.open, but I was told that they are deprecated and shouldn’t be used.
What do I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should place dedicated window name (target as second argument to .open) to your opened window, so browser would know to replace it instead of opening new window:

    const winUrl = URL.createObjectURL(new Blob([final_file], { type: "text/html;charset=utf8" }));
    const win = window.open(winUrl, 'my-window');

target is not deprecated.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading