Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  113] [ 6]  / answers: 1 / hits: 36513  / 11 Years ago, sun, january 12, 2014, 12:00:00

How to redirect user to an absolute url in angularjs.



For example:
i have a page, my current url (http://example.com/submit),
once the user click some button in the web page, he has to get redirected to some other web page for example ('http://google.com').



I tried using



$location.absUrl() == 'http://www.google.com'
$location.path('http://www.google.com')
$location.url('http://www.google.com')


But nothing works.



Note:
The rediretion should not occur from the web-server. Its an REST API.
Wanted to achieve in client side(using angularjs) if the user is valid user(authenticated user), redirected him to portal)



Thanks


More From » angularjs

 Answers
13

You need to use the browser level API, with the object window, or you can inject the $window reference in your controller.




  • window.location.href=http://www.google.com;

  • $window.location.href=http://www.google.com;



References:



window



$window



Best solution should be perform redirect in your $routeProvider configuration, injecting the $window object and performing all redirection you need.


[#73228] Friday, January 10, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristiano

Total Points: 652
Total Questions: 94
Total Answers: 108

Location: Suriname
Member since Sun, Jun 13, 2021
3 Years ago
;