问题:
Morning.
Guys i have tried window.history.pushState('', '', site_url+''+ActivityUrl);, also window.history.replaceState('', '', site_url+''+ActivityUrl);
I need to upda...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
Morning.
Guys i have tried window.history.pushState('', '', site_url+''+ActivityUrl);
, also window.history.replaceState('', '', site_url+''+ActivityUrl);
I need to update the url in the browser without redirecting to it. All the solutions i had got are the above two but this is not working and also not displaying any errors.
The code i'm using is in a Angular-js controller.
$scope.updateUrl = function (ActivityUrl) {
window.history.pushState('', '', site_url+''+ActivityUrl);
}
and calling this function with a ng-click.
Please help.
回答1:
At first, need to set configuration for location provider
// Configure $locationProvider html5Mode
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode({ enabled: true, requireBase: false, rewriteLinks: false });
}]);
and then change your method as :
$scope.updateUrl = function (ActivityUrl) {
$window.history.pushState('', '', site_url+''+ActivityUrl);
}