Skip to content

Commit 297399a

Browse files
committed
add window location service
1 parent 33efe01 commit 297399a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export class WindowLocationService {
2+
3+
public static changeLocation(destination: string): void {
4+
window.location.assign(destination);
5+
}
6+
7+
public static changeLocationAfterPageLoad(destination: string): void {
8+
// Wait for resources to load before redirect. Without this Safari would fail
9+
// to load/activate resources, like fonts.
10+
const waitForPageLoad = () => {
11+
if (document.readyState === 'complete') {
12+
WindowLocationService.changeLocation(destination);
13+
} else {
14+
setTimeout(waitForPageLoad, 500);
15+
}
16+
};
17+
waitForPageLoad();
18+
}
19+
20+
public static getHashQueryString(): string {
21+
return window.location.hash.substring(1);
22+
}
23+
24+
public static getLocationOrigin(): string {
25+
if (window.location.origin) {
26+
return window.location.origin;
27+
}
28+
// IE11 fix, when window.location.origin is undefined
29+
let locationOrigin = `${window.location.protocol}//${window.location.hostname}`;
30+
locationOrigin += window.location.port ? ':' + window.location.port : '';
31+
return locationOrigin;
32+
}
33+
}

0 commit comments

Comments
 (0)