[英]window.open + Opening content in 2 tabs
I'm using angular js and javascript in my application.And here , when I click <a>
tag it call a method in angular controller ,which has $window.open();
我在应用程序中使用angular js和javascript。在这里,当我单击
<a>
标记时,它将在angular controller中调用一个具有$window.open();
. 。 Every time I click it content open in 2 tabs .What is the reason for that?
每次单击它时,都会在2个选项卡中打开内容 。这是什么原因? Please help me out.
请帮帮我。
HTML 的HTML
<li><a href="#" id="test_home" ng-click="test_home()">Test Click</a></li>
Angular controller 角度控制器
controllers.controller('LogoutCtrl', ['$scope', '$location','$cookieStore','$rootScope','$window',
function($scope, $location,$cookieStore,$rootScope ,$window) {
$scope.test_home = function () {
$window.open('www.yahoo.com');
};
}
]);
Try using preventDefault: 尝试使用preventDefault:
$scope.test_home = function (e) {
e.preventDefault();
$window.open('www.yahoo.com');
};
Or, use return false;
或者,使用
return false;
Nothing in common with $window.open
, maybe some other event listener is bind to #test_home
or some browser plugin is responsible for it. 与
$window.open
没什么共同之处,也许其他事件侦听器绑定到#test_home
或某些浏览器插件对此负责。
Short example on jsfiddle shows that method will open only one window / tab. jsfiddle上的简短示例显示该方法将仅打开一个窗口/选项卡。
angular.module('windowOpen', []).controller('open', function ($scope, $window) {
$scope.openMe = function () {
$window.open('http://google.com/');
};
});
jsfiddle: http://jsfiddle.net/krzysztof_safjanowski/AKB4c/ jsfiddle: http : //jsfiddle.net/krzysztof_safjanowski/AKB4c/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.