【问题标题】:AngularJS: Trying to open page in new window/tab after $http success is prevented by popup blockerAngularJS:弹出阻止程序阻止$http成功后尝试在新窗口/标签中打开页面
【发布时间】:2017-03-13 16:53:05
【问题描述】:

在让用户通过 AngularJS 表单提交信息后,我试图在新选项卡/页面中打开一个窗口。但是,Chrome 的弹出窗口阻止程序阻止了该操作。

这是我的$http 请求部分在我的app.js

// function to process the form
$scope.processForm = function() {
    $http({
      method  : 'POST',
      url     : 'docusign.php', // PHP script generates URL from form data
      data    : $scope.user  // pass in data as strings

     })
      .success(function(data) {
            window.open(data); // this gets prevented by Chrome's popup blocker
            //The root of the new page I'm trying to open is https://www.docusign.net
            // -- Am I getting a pop-up block because I'm trying to take the user to a 
            // different website?
        });
};

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:
    // function to process the form
    $scope.processForm = function() {
        $http({
          method  : 'POST',
          url     : 'docusign.php', // PHP script generates URL from form data
          data    : $scope.user,  // pass in data as strings
          async   : false
    
         })
          .success(function(data) {
                window.open(data, '_blank'); // this gets prevented by Chrome's popup blocker
            });
    };
    

    【讨论】:

    • 收到同样的弹窗问题
    • data 的内容是什么,应该只是一个 URL 字符串
    • 原来这是由于这次调用 stackoverflow.com/a/19279442/2840591 的异步性质,我编辑了我的答案以反映这一点
    • datahttps://www.docusign.net/member/PowerFormSigning.aspx?PowerFormId={someId}&Merchant-Reseller_UserName={someName}&Merchant-Reseller_Email={someEmail}形式的URL
    • async: false 仍然存在弹出框问题
    猜你喜欢
    • 1970-01-01
    • 2011-10-31
    • 2017-02-13
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多