废话不多说,,上代码
try {
const a = window.document.createElement('a');
// 判断是否有参数
if (search) {
a.setAttribute('href', `${url}?${search}`);
} else {
a.setAttribute('href', `${url}`);
}
a.setAttribute('target', '_blank');
a.setAttribute('id', url);
// 防止反复添加
if (!window.document.getElementById(url)) {
window.document.body.appendChild(a);
}
a.click();
} catch (e) {
console.error(e.message);
}
代码仅供参考