2016-06-30 26 views
-1

当前窗口喜这是我的当前代码,其中i有弹出一旦我取消弹出我不得不关闭整个应用程序选项卡,这意味着该窗口window.close如何关闭在角

<!doctype html> 
<html ng-app="plunker"> 
    <head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js"></script> 
    <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script> 
    <script src="example.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet"> 
    </head> 
    <body> 

    <script> 
     angular.module('plunker', ['ui.bootstrap']); 
     var ModalDemoCtrl = function ($scope, $modal, $log) { 

      /* Note: The hard coded user object has been commented out, as 
      it is now passed as an object parameter from the HTML template. 
      */ 
      /* $scope.user = { 
       user: 'name', 
       password: null 
      };*/ 

      $scope.open = function (user) { 
       $scope.user = user; 
       $modal.open({ 
        templateUrl: 'myModalContent.html', 
        backdrop: true, 
        windowClass: 'modal', 
        controller: function ($scope, $modalInstance, $log, user) { 
         $scope.user = user; 
         $scope.submit = function() { 
          $log.log('Submiting user info.'); 
          $log.log(JSON.stringify(user)); 
          $modalInstance.dismiss('cancel'); 
         } 
         $scope.cancel = function() { 
          $modalInstance.dismiss('cancel'); 
         window.open('location', '_self', ''); 
         window.close(); 
         }; 
        }, 
        resolve: { 
         user: function() { 
          return $scope.user; 
         } 
        } 
       }); 
      }; 
     }; 
    </script> 

    <div ng-controller="ModalDemoCtrl"> 
     <script type="text/ng-template" id="myModalContent.html"> 
      <div class="modal-header"> 
       <h3>I'm a modal!</h3> 
      </div> 
      <form ng-submit="submit()"> 
      <div class="modal-body"> 
       <label>User name</label> 
       <input type="text" ng-model="user.user" /> 
       <label>Password</label> 
       <input type="password" ng-model="user.password" /> 
      </div> 
      <div class="modal-footer"> 
       <button class="btn btn-warning" ng-click="cancel()">Cancel</button> 
       <input type="submit" class="btn primary-btn" value="Submit" /> 
      </div> 
      </form> 
     </script> 

     <button class="btn" ng-click="open({user: 'username', password: 'password'})">Open me!</button> 
     <div ng-show="user.password">Got back from modal: {{ user | json}}</div> 
    </div> 
    </body> 
</html> 

这个代码不工作的任何帮助,请

window.close()的工作不

+0

请参阅http://plnkr.co/edit/d1VhZhjdBPPEHn2sVJBK?p=preview –

+0

comeon阅读我的问题我说需要关闭窗口而不是弹出 –

+0

它会抛出什么错误? –

回答

0

使用$window.close()$window服务。

你在问关于角模态。 使用这种

$modalInstance.dismiss('cancel'); or $modalInstance.close(); 

阅读以了解更多信息modal

+0

检查我的代码之前,我的答案我试图不工作 –

0

window.close只能通过关闭应用程序打开窗户,而不是由用户打开的窗口/标签。这意味着当用户访问您的网站他/她打开窗口,而不是您的应用程序。但是如果你用window.open使用javascript打开一个新窗口,你可以用window.close关闭。这是出于安全原因而完成的,并且内置于几乎所有最新的浏览器中。

+0

检查我的代码之前答案我试图不工作 –

+0

上述解决方案不是一个答案 –

+0

我检查过。多数民众赞成我说你是在用户打开使用'_self'在同一窗口中打开新窗口。该窗口未被您的应用打开。 – raj

相关问题