Javascript 在FF上重新加载页面不更改页面
我遇到了一个问题,我不知道发生了什么: 我用的是Angular和它的路由机制 所以我有一个网址:Javascript 在FF上重新加载页面不更改页面,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我遇到了一个问题,我不知道发生了什么: 我用的是Angular和它的路由机制 所以我有一个网址: <a href="#/videos/detail/{{video.Id}}" onclick="location.reload();"> <div class="card-image"> <img ng-src="{{video.ThumbnailUrl?video.ThumbnailUrl:'img/images.png'}}" src=""
<a href="#/videos/detail/{{video.Id}}" onclick="location.reload();">
<div class="card-image">
<img ng-src="{{video.ThumbnailUrl?video.ThumbnailUrl:'img/images.png'}}" src="" />
</div>
</a>
指令是这样的
.directive('videoCard', function () {
return {
restrict: 'E',
templateUrl: 'partials/directives/video-card.html',
controller: function ($scope, $element, $location) {
$scope.redirectWithReload = function (url) {
var toUrl = location.href.split('#')[0] + url;
location.replace(toUrl);
}
},
compile: function () {
return {
post: function () {
$('a.prevent').click(function (e) {
e.preventDefault();
});
}
}
}
};
})
类prevent
只是为了我的Jquery防止默认值
然后点击ng,因为如果我需要在url中添加更多变量,现在很容易做到:)
谢谢你的帮助!特别是:@mplungjan您能在onclick中尝试以下任何一种吗:
window.location.href = "your_page.html" + "?" + Date.parse(new Date());
此方法确保不使用任何缓存页面,每当需要通过JS重新加载页面时,我都会应用此方法。要强制呈现页面,您可以使用:
$route.reload();
参见:
导致$route服务重新加载当前路由,即使$location未更改
因此,ngView创建新的作用域,重新实例化控制器
您可以在控制器中添加具有所需功能的方法:
// view
<a ng-click="redirectWithReload('#/videos/detail/'+video.Id)">
// controller
$scope.redirectWithReload = function(url) {
$location.url(url); // use $location service
}
//查看
//控制器
$scope.redirectWithReload=函数(url){
$location.url(url);//使用$location服务
}
如果将ID存储在属性中并使用replace,则可以执行以下操作
<a href="#" id="{{video.Id}}"
onclick="location.replace(location.href.split('#')[0]+'#/videos/detail/'+this.id); return false">
有关更多参数:
<a href="#" class="vids" data-id="{{video.Id}}" data-target="somewhere">
它应该做什么?#是一个锚。页面上的脚本应该对此做出反应。我看不到location.reload的用途。尝试删除it@mplungjan:重定向然后刷新请阅读我的修订评论这是一个XY问题。解决您需要重新加载插件的原因。@mplungjan我已经花了2周的时间试图修复插件,除此之外还有1个月的时间来解决我为什么需要该插件的问题。所以这已经是一个修复一个修复:p他们做了完全相同的事情,所以在这里没关系这可以工作,但这是在一个指令中,所以我正在寻找将其添加到指令代码中。关于如何添加多个变量的快速建议吗?我刚刚注意到页面没有使用location.replace()刷新。这是正常的行为吗?(我使用的是$(this).data()thingyHmm,如果不是,那么就按照被否决的帖子上的建议添加一个新的日期().getTime(),但要确保它有正确的前导字符(&或/取决于你如何解析你的URL)
<a href="#" class="vids" id="{{video.Id}}">
$(function() {
$(".vids").on("click",function(e) {
e.preventDefault();
location.replace(location.href.split('#')[0]+'#/videos/detail/'+this.id); "
});
});
<a href="#" class="vids" data-id="{{video.Id}}" data-target="somewhere">
$(function() {
$(".vids").on("click",function(e) {
e.preventDefault();
location.replace(location.href.split('#')[0]+'#/videos/detail/'+
$(this).data("id")+'/'+
$(this).data("target"));
});
});