blob: aa8191bb089173db9d97937d8790cc9710258485 (
plain)
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
|
// Get either the actual page URL or the declared canonical URL (geturl.js)
HashOverConstructor.getURL = function (canonical)
{
canonical = (canonical !== false);
// Get the actual page URL
var url = window.location.href.split ('#')[0];
// Return the actual page URL if told to
if (canonical === false) {
return url;
}
// Otherwise, return the declared canonical URL if available
if (typeof (document.querySelector) === 'function') {
var canonical = document.querySelector ('link[rel="canonical"]');
if (canonical !== null && canonical.href !== undefined) {
url = canonical.href;
}
} else {
// Fallback for old web browsers without querySelector
var head = document.head || document.getElementsByTagName ('head')[0];
var links = head.getElementsByTagName ('link');
for (var i = 0, il = links.length; i < il; i++) {
if (links[i].rel === 'canonical') {
url = links[i].href;
break;
}
}
}
return url;
};
|