场景:

点击后端返回的非本系统的网络链接并跳转,要求在新页面打开。如果是本标签打开直接window.location.href ="/url"。但是现在要求新标签页,window.open有浏览器限制。

 

解决方法:

  element ui 的头部下拉框的点击事件
        handleCommand(command) {
            if (command == '商户中心') {
                merchantCenter().then((res) => {
                    let urlHref = res.data;
                    // window.location.href = urlHref;
                    this.createSuperLabel(urlHref,'shop');
                });
            }
        },
创建元素跳转
        createSuperLabel(url, id) {
            let a = document.createElement('a');
            a.setAttribute('href', url);
            a.setAttribute('target', '_blank');
            a.setAttribute('id', id);
            // 防止反复添加
            if (!document.getElementById(id)) {
                document.body.appendChild(a);
            }
            a.click();
        }

 

更多推荐