6 examples of 'javascript get referrer' in JavaScript

Every line of 'javascript get referrer' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
242function makeReferrer(url, hashObj) {
243 var referrer = '';
244 var conjMark = url.indexOf('?') < 0 ? '?' : '&';
245 var urlData = '';
246 for (var key in hashObj) {
247 urlData += '&' + key + '=' + hashObj[key];
248 }
249 urlData = urlData.slice(1);
250 if (url.indexOf('#') < 0 && urlData) {
251 referrer = url + conjMark + urlData;
252 }
253 else {
254 referrer = url.replace('#', conjMark + urlData + '#');
255 }
256 return referrer;
257}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

116function getReferrerUrl() {
117 let referer = '';
118 if (window.self !== window.top) {
119 try {
120 referer = window.top.document.referrer;
121 } catch (e) { }
122 } else {
123 referer = document.referrer;
124 }
125 return referer;
126}
151function getDomain(referer) {
152 if (referer) {
153 let domainA = document.createElement('a');
154 domainA.href = referer;
155 return domainA.hostname;
156 }
157}
3function getUrl (r, forBrowser) {
4 if (!r) return null
5 if (/^[\w-]+\/[\w\.-]+(#[a-z0-9]*)?$/.test(r)) {
6 if (forBrowser)
7 r = r.replace("#", "/tree/")
8 return "https://github.com/" + r
9 }
10
11 return null
12}
7public async getUrl(): Promise<UrlWithStringQuery> {
8 return parse(await page.evaluate('location.href'));
9}
11function getRefererDomain() : string {
12 return (window.xprops && window.xprops.getParentDomain)
13 ? window.xprops.getParentDomain()
14 : window.location.host;
15}

Related snippets