重新打开已存在的窗口

需求:

在A页面中选择一个对象,查看详情时打开一个新的浏览器网页。

再次在A页面中选择同一个对象,打开查看该对象时,要将之前打开的页面再次置前,而不是为同一个对象打开多个页面窗口。

思路:

在A页面保存所有打开的窗口对象,在打开窗口之前判断该页面是否已存在,如果已存在就选中该页面置前,如果不存在就打开一个新的窗口。

childWindow: any[] = [];

GoToDetails(object: any): void {
       const url = './app/details?id=' + object.id;
       // 过滤掉已关闭的窗口
       this.childWindow = this.childWindow.filter(e => !window.closed);
      // 查找窗口是否已存在
       const winIndex = this.childWindow.findIndex(item =>
               item.location !== null && ('.' + item.location.pathname + item.location.search) === url);
       if (winIndex !== -1) {
         // 将已存在的窗口置前
           this.childWindow[winIndex].focus();
           this.childWindow[winIndex].resizeTo(1282, 1000);
           this.childWindow[winIndex].moveTo(0, 0);
           return;
       }
      // 若不存在则创建一个窗口,并将保存到数组中
       const editWindow = window.open(url, '_blank',
             'toolbar=no, location=no, directories=no, status=no, ' +
              'menubar=no, scrollbars=yes, resizable=no, width=1282, height=1000');
      this.childWindow.push(editWindow);     
 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值