Home > Software design >  Replacing a tab with a different one using JS
Replacing a tab with a different one using JS

Time:04-14

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?

CodePudding user response:

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.

  • Related