vue打開新tab


通過觸發隱藏的a標簽的click事件打開

<a ref="mytarget" class="hidetarget" href="" target="_blank" rel="noopener noreferrer"></a>

<xx @click.native="openNewTab('http://xxx')"></xx>



  openNewTab(url) {
      let target = this.$refs.mytarget
      target.setAttribute('href', url)
      target.click()
    },


  .hidetarget {
    width: 0;
    height: 0;
  }

 

 

另一種打開新窗口,並指定窗口大小(谷歌瀏覽器測試有效)

  openNewWindow(newUrl) {
      const winW = 1920
      const winH = 1080
      const leftValue = (window.innerWidth - winW) / 2
      const topValue = (window.innerHeight - winH) / 2
      window.open(
        newUrl,
        '_blank',
        'menubar=no,toolbar=no,status=no,scrollbars=yes,titlebar=no,width=' +
          winW +
          ',height=' +
          winH +
          ',left=' +
          leftValue +
          ',top=' +
          topValue
      )
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM