forked from InteractiveAdvertisingBureau/CCPA-reference-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiframe.html
56 lines (53 loc) · 1.64 KB
/
iframe.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
<html>
<meta charset="UTF-8">
<script>
function setResult(resultHtml) {
var res = document.getElementById("result");
if(res) {
res.innerHTML = resultHtml;
} else {
window.addEventListener('DOMContentLoaded', (e) => {
setResult(resultHtml);
});
}
}
window.addEventListener('message', (event) => {
const data = event && event.data && event.data.__uspapiReturn;
if (data)
if (data.success && data.returnValue.uspString) {
setResult("uspstring = \"" + data.returnValue.uspString + "\" 🤔");
} else {
setResult("error retrieving the uspString");
}
}, false);
var frame = window;
var cmpFrame;
while(frame) {
try {
if(frame.frames['__uspapiLocator']) {
cmpFrame = frame;
break;
}
} catch(ignore) {}
if(frame === window.top) {
break;
}
frame = frame.parent;
}
if(cmpFrame) {
cmpFrame.postMessage({
__uspapiCall: {
callId: Math.random(),
command: 'getUSPData',
version: 1
}
}, '*');
} else {
setResult("could not find usapiLocator frame ancestor");
}
</script>
<body style="background-color: #e3f2fd">
<b>iframe content</b>
<p id="result">uspString not yet retrieved</p>
</body>
</html>