且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在新窗口中打开链接后如何使用JavaScript更改href属性?

更新时间:2023-02-18 11:16:38

Your onclick fires before the href so it will change before the page is opened, you need to make the function handle the window opening like so:

function changeLink() {
    var link = document.getElementById("mylink");

    window.open(
      link.href,
      '_blank'
    );

    link.innerHTML = "facebook";,
    link.setAttribute('href', "http://facebook.com");

    return false;
}

相关阅读

技术问答最新文章