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