forked from tugayilik/unification
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.html
30 lines (26 loc) · 789 Bytes
/
helper.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Helper</title>
<script type="text/javascript">
let callbacks = {
setUserId: () => {
if (localStorage.getItem('userId') === null) {
localStorage.setItem('userId', Math.random().toString().substr(2));
}
},
getUserId: () => {
window.parent.postMessage(localStorage.getItem('userId'), '*')
}
}
window.addEventListener('message', () => {
callbacks[event.data]();
});
// Set User Id by default when frame loaded
// It can be triggered from parent frame also
callbacks.setUserId();
</script>
</head>
<body></body>
</html>