Skip to content

Commit 26c6f27

Browse files
authored
Merge pull request #2 from readyplayerme/feature/instructions
Instructions and Closing window
2 parents 97c5cd7 + da71204 commit 26c6f27

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/iframe.html

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
.content {
1010
margin-top: 10px;
1111
border: none;
12-
width: 100%;
13-
height: calc(100% - 80px);
12+
width: 100%;
13+
height: calc(100% - 250px);
1414
}
1515

1616
#avatarUrl {
1717
margin-top: 10px;
1818
}
1919

2020
body {
21-
padding: 40;
21+
padding: 20 40;
2222
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
2323
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
2424
background-color: rgb(243, 243, 243);
@@ -27,39 +27,46 @@
2727

2828
<script>
2929
// Change this to your custom subdomain
30-
const iframeUrl = "https://demo.readyplayer.me/"
30+
const iframeUrl = 'https://demo.readyplayer.me/'
3131

32-
window.addEventListener("message", receiveMessage, false)
32+
// Listen to messages from the iframe
33+
window.addEventListener('message', receiveMessage, false)
3334

35+
// Handle messages from the iframe
3436
function receiveMessage(event) {
35-
setTimeout(() => {
36-
// Get URL to avatar
37-
if (iframeUrl.includes(event.origin)) {
38-
console.log(`Avatar URL: ${event.data}`)
39-
document.querySelector(
40-
"#avatarUrl"
41-
).innerHTML = `Avatar URL: ${event.data}`
42-
}
43-
}, 1000);
37+
// Get URL to avatar
38+
const url = event.data
39+
console.log(`Avatar URL: ${url}`)
40+
document.querySelector('#avatarUrl').innerHTML = `Avatar URL: ${url}`
41+
document.querySelector('.container').removeChild(iframe)
4442
}
4543

46-
function makeAvatar() {
47-
let iframe = document.getElementById("iframe")
44+
function loadIframe() {
45+
let iframe = document.getElementById('iframe')
46+
4847
if (!iframe) {
49-
iframe = document.createElement("iframe")
50-
document.querySelector(".container").appendChild(iframe)
48+
iframe = document.createElement('iframe')
49+
document.querySelector('.container').appendChild(iframe)
5150
}
52-
iframe.id = "iframe"
51+
iframe.id = 'iframe'
5352
iframe.src = iframeUrl
54-
iframe.className = "content"
55-
iframe.allow = "camera *; microphone *"
53+
iframe.className = 'content'
54+
iframe.allow = 'camera *; microphone *'
5655
}
5756
</script>
5857
</head>
5958

6059
<body>
61-
<input type="button" value="Open Ready Player Me" onClick="makeAvatar()" />
62-
<div id="avatarUrl">Avatar URL:</div>
60+
<h2>Ready Player Me iframe example</h2>
61+
<ul>
62+
<li>Click "Open Ready Player Me" button.</li>
63+
<li>Create an avatar.</li>
64+
<li>Click on "Done" button when you finish customizing your avatar.</li>
65+
<li>This page will receive the url when it is created.</li>
66+
<li>Url will be displayed, and Ready Player Me window will be closed.</li>
67+
</ul>
68+
<input type="button" value="Open Ready Player Me" onClick="loadIframe()" />
69+
<div id="avatarUrl"><b>Avatar URL: </b></div>
6370
<div class="container"></div>
6471
</body>
6572
</html>

0 commit comments

Comments
 (0)