-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (34 loc) · 840 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* global module */
/**
* Returns referrer from current page
*
* @returns {string} - referrer of current page
*/
function findReferrer () {
var oFrame = window
var exception = false
if (oFrame.top === oFrame.self) {
return oFrame.location.href
} else {
try {
while (oFrame.parent.document !== oFrame.document) {
// Check if document property is accessible.
if (oFrame.parent.document) {
oFrame = oFrame.parent
} else {
// If document was not set, break the loop and set exception flag.
exception = true
break
}
}
} catch (e) {
exception = true
}
if (exception) {
return oFrame.document.referrer || oFrame.location.href
} else {
return oFrame.location.href
}
}
}
module.exports = findReferrer