【发布时间】:2021-11-11 04:05:33
【问题描述】:
目标:在不重新加载页面的情况下更改 URL,因为 URL 用于以后的功能,但无法轻松更改来自其他位置的重新链接。
环境:ServiceNow 实例(这就是为什么语法在某些时候对你们来说可能有点奇怪。
我需要在阻止一次之后对 $locationChangeStart 的事件处理进行反应。
知道如何恢复e.preventDefault() 功能吗?
代码:
var originalUrl, initUrl;
$rootScope.$on("$locationChangeStart", function(e, newUrl){
if(newUrl != originalUrl && newUrl != initUrl && c.count<c.maxCount ){
$window.history.replaceState(newUrl, $document.title, newUrl);
c.count++;
}
originalUrl = newUrl;
e.preventDefault();
$timeout(function(){
console.log("unbind")
//Both not working
$().unbind(preventDefault);
e.returnValue = true;
},2000)
});
$scope.changeURL = function(){
initUrl = $location.absUrl();
var params = $location.search();
params.o=$scope.data.sort_fields;
params.d=$scope.data.sort_direction;
params.initial_load= true;
//triggers the $locationChangeStart event
$location.search($httpParamSerializer(params));
}
$scope.changeURL()
【问题讨论】:
标签: preventdefault revert