undefinedfix
Sign in

How to open a new window with Vue programming navigation window.open

m0ebius edited in Thu, 18 Aug 2022

In the code, the effect you want to achieve is not allowed in the project window.open Is there any other way?

3 Replies
g0lg0th7
commented on Thu, 18 Aug 2022
  /**
   * 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()
  }
Ganesh
commented on Thu, 18 Aug 2022

Click the a tag target=_ blank

openHBP
commented on Thu, 18 Aug 2022

JS create an a tag?