项目中翻开新窗口的3种体式格局

1.运用iframe(注重Iframe的高度默许150px,假如要转变iframe的高度,只能设置成详细的像素值,不能是百分比)

2.运用window.open()直接翻开外部窗口,在外部窗口中处置惩罚完成一切的操纵后回到本来的页面,本来的页面涌现一个确认是不是完成操纵的弹框。点击确认或许“cancel”以后接着挪用其他的接口。

3.运用window.open()在当前窗口翻开另一个窗口,在新开窗口中操纵完成以后,封闭该窗口,在当前窗口中监听新窗口什么时候封闭,一旦检测到窗口封闭就实行回调。
运用这类体式格局须要斟酌浏览器的跨域题目,在ie上假如运用window.open()翻开跨域了的窗口,window.open()是猎取不到window对象的。

detectCreditCardFilledOut: (callback, url, openWin) => {
  let creditCarWin = null;

  let s = null;

  const stopF = () => {
    clearInterval(s);
    creditCarWin = null;
    s = null;
    callback();
  };


  const checkCloseWindowOrNot= () => {
    if (creditCarWin != null && creditCarWin.closed) {
      stopF();
    }
  };


  const openCreditCard = () => {
    try {
      creditCarWin = openWin(url, 'CreditCard');
      creditCarWin.focus();
      runF();
    } catch (e) {
      Util.NotificationUtil('error', {
        description: lang.openWindowError
      })
    }
  };

  const runF = () => {
    s = setInterval(checkCloseWindowOrNot, 500);
  };

  openCreditCard();
},
    原文作者:qinqinlv
    原文地址: https://segmentfault.com/a/1190000018214370
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞