为什么 Safari 会阻止弹出窗口?

时间:2021-02-15 19:01:10

标签: javascript browser popup

我实施了此程序以避免在浏览器中阻止弹出窗口。由于用户操作,它即将打开一个新窗口,但稍后在 ajax 请求完成时用内容填充它。

https://www.yaplex.com/blog/avoid-browser-pop-up-blockers

不幸的是,它只适用于 Chrome 而不是 Safari。你知道为什么吗?

export const startPayment = (data, allowNewTab) => {
  let url = BEUrl + "startPayment/";
  let barionWindow;
  if (allowNewTab) {
    let id = new Date().getTime();
    barionWindow = window.open(
      window.location.href,
      "_blank",
      "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600,left = 240,top = 212"
    );
  }

  axios({
    method: "post",
    url: url,
    data: data,
    headers: { "Content-Type": "application/json", crossDomain: true },
  })
    .then((data) => {
      if (data.data.GatewayUrl) {
        if (allowNewTab) {
          barionWindow.location.replace(data.data.GatewayUrl);
        } else {
          window.location.replace(data.data.GatewayUrl);
        }
      }
    })
    .catch((err) => console.error(err));
};

我们是否将完成处理程序方法与 ANYC 混合使用?

0 个答案:

没有答案
相关问题