如果你要离开你的页面,我猜你有两种处理方式。
第一个可能是在离开页面之前强制您的页面到一个引用 ID 的位置。
即:单击 -> location.href('#myItemId') -> location.href('externalResource')。
http://jsfiddle.net/romulocollopy/gj2rss1v/6/
angular.module('myapp',[])
.controller("myCtrl",['$scope',function($scope){
$scope.fruits = ['banana','aple','passion fruit', 'watermelon', 'spam','eggs'];
$scope.link_to_fruit_detail = function(fruit){
location.href = '#/fruit';
location.href = 'http://www.'+fruit+'.com';
}
}]);
另一种方法是将点击的 y 位置存储在 cookie 中:
http://jsfiddle.net/romulocollopy/gj2rss1v/7/
angular.module('myapp',['ngCookies'])
.controller("myCtrl",['$scope', '$cookieStore',function($scope, $cookieStore){
if ( $cookieStore.get('y-click') ){
var y = $cookieStore.get('y-click')
window.scrollTo(y,0);
console.log(y)
}
$scope.fruits = ['banana','aple','passion fruit', 'watermelon', 'spam','eggs'];
$scope.link_to_fruit_detail = function($event, fruit){
location.href = 'http://www'+fruit+'.com';
$cookieStore.put('y-click', $event.y);
}
}]);
展位有利有弊,但我想不出更好的方式。