-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (55 loc) · 2.45 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<h3>SDK iFrame:</h3>
<div id="messages"></div>
<script type="text/javascript">
//This function is called whenever the window receives a message event, the message object is passed in as it's only parameter
function receiver(message) {
console.log("inside iframe, received: " + message.data)
console.log("inside iframe, received from " + message.origin)
//get the message container html element (in this case, the messages div)
var messagecontainer = document.getElementById("messages");
//Get the time of message receipt
var currenttime = new Date();
//format the time into a user readable format
var formattedtime = currenttime.getHours() + ":" + currenttime.getMinutes() + ":" + currenttime.getSeconds();
var msgcontent = message.data;
//check the content of the message only contains letters and numbers to prevent xss attacks
if (msgcontent.match(/^[A-Za-z0-9]+$/)) {
//if no illegal characters are found in the message, print it to the message container div along with the time of receipt
messagecontainer.innerHTML += "message received @ " + formattedtime + ": " + message.data + "<br />";
console.log("inside iframe, updating cookie");
setCookie("projectCookie", message.data, 1000);
// parent.postMessage(getCookie("projectCookie"), "*");
} else {
//if illegal characters are found in the message content, print an error message to the message container
messagecontainer.innerHTML += "Illegal characters found in the message received @ " + formattedtime + ". Message rejected<br/>";
}
}
//Add an event listener to the window object to catch any message events
window.addEventListener('message', receiver, false);
if (getCookie("projectCookie") == null) {
setCookie("projectCookie", "initialValue", 1000);
}
function setCookie(cname, cvalue, exdays) {
localStorage.setItem(cname, cvalue);
/*
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
*/
}
function getCookie(cname) {
return localStorage.getItem(cname);
/*
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name)==0) {
return c.substring(name.length,c.length);
}
}
return null;*/
}
parent.postMessage(getCookie("projectCookie"), "*");
</script>