Target: Changing the URL without reloading the page because the URL is used for later functionalities but the relinks from other locations can't be changed easily.
Enviroment: ServiceNow instance (that's why the syntax may look a bit weird to you guys at some points.
I need to reactive the event handling for the $locationChangeStart
after preventing it once.
Any idea how to revert the e.preventDefault()
functionality?
Code:
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()