使用JavaScript在新窗口打开链接

有时候,需要使用JavaScript代码来实现在新窗口中打开链接,具体代码如下:

let id = 'buy_url_id';
let a = document.createElement("a");
a.setAttribute("href", Config.admin_data.buy_url);
a.setAttribute("target", "_blank");
a.setAttribute("id", id);
if(!document.getElementById(id)) {
    document.body.appendChild(a);
}
a.click();