How to get a referrer URL on Angular 4?? For example say example.com is my angular website, if example.com is visited from an another php page say domaintwo.com/checkout.php. How can I identify the the referenced url(domaintwo.com/checkout.php) from my angular website..?? Am looking for a solution like $_SERVER['HTTP_REFERER']
on PHP(same process needed on angular4). Thanks in Advance
Asked
Active
Viewed 1.3k times
4

Sreejesh T S
- 89
- 2
- 4
- 12
-
Why do you need the referrer in your client script? – bitsprint May 01 '18 at 11:13
-
What's the error you get when you use document.referrer? Is there any compilation error? Share more details... – Aniket Suryavanshi Dec 07 '18 at 15:33
-
@bitsprint because you may have a static cached HTML / JS website that doesn't run any server side code on a new session - and there's nowhere else to get it – Simon_Weaver Jun 15 '19 at 01:24
1 Answers
11
Have you tried?
document.referrer
According to W3C:
referrer of type DOMString, readonly
Returns the URI [IETF RFC 2396] of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark).

Mike Doe
- 16,349
- 11
- 65
- 88
-
4note that a referal from HTTPS > HTTP doesn't provide the referrer to you https://stackoverflow.com/questions/16551586/can-you-at-least-get-the-domain-of-the-https-referer – Simon_Weaver Jun 15 '19 at 01:26