美文网首页
js打开新页面

js打开新页面

作者: AI视客 | 来源:发表于2021-11-25 00:31 被阅读0次
window.onload = function() {
    let uri = "http://www.baidu.com";
    let id = "new_a"
    createSuperLabel(uri, id)
}

function createSuperLabel(url, id) {
    let a = document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("target", "_blank");
    a.setAttribute("id", id);
    // 防止反复添加      
    if (!document.getElementById(id)) {
        document.body.appendChild(a);
    }
    a.click();
}

相关文章

网友评论

      本文标题:js打开新页面

      本文链接:https://www.haomeiwen.com/subject/mexatrtx.html