/** * a模拟window.open,不会被浏览器拦截 * @param {String} url a标签打开的地址 * @param {String} id a标签的ID * @param {String} targetType a标签点击打开的方式(当前页面打开还是新窗口打开) */ openWindow: (url, targetType = '_blank', id = 'open') => { // 如果存在则删除 if (document.getElementById(id)) { document.body.removeChild(document.getElementById(id)) } const a = document.createElement('a') a.setAttribute('href', url) // a.setAttribute('download', url) a.setAttribute('target', targetType) a.setAttribute('id', id) document.body.appendChild(a) a.click() }