Open xlearns opened 2 years ago
function fn(link){ const $a = document.createElement("a"); $a.setAttribute("href", link); $a.setAttribute("target", "_blank"); $a.setAttribute("rel", "noreferrer noopener"); $a.setAttribute("id", "external"); document.getElementById("external") && document.body.removeChild(document.getElementById("external")); document.body.appendChild($a); $a.click(); $a.remove(); }; fn('baidu.com')
那么请问location.href跳转和给a标签设置点击事件有什么区别呢?
用a标签具体实现: