workadventure/maps/tests/iframe.html
David Négrier 330a795fee Trying to find iframe_api.js URL script dynamically
This would allow us to have tests that don't rely on the iframe_api.js from prod, and would allow scripts that target the correct iframe API, no matter if they are running on workadventu.re or on self-hosted maps.
2021-06-28 11:51:13 +02:00

32 lines
1,011 B
HTML

<!doctype html>
<html lang="en">
<head>
<script>
var script = document.createElement('script');
script.setAttribute('src', document.referrer + 'iframe_api.js');
script.defer = false;
script.async = false;
document.head.appendChild(script);
</script>
</head>
<body>
<button id="sendchat">Send chat message</button>
<script>
document.getElementById('sendchat').onclick = () => {
WA.chat.sendChatMessage('Hello world!', 'Mr ROBOT');
}
</script>
<div id="chatSent"></div>
<script>
window.addEventListener('load', () => {
WA.chat.onChatMessage((message => {
const chatDiv = document.createElement('p');
chatDiv.innerText = message;
document.getElementById('chatSent').append(chatDiv);
}));
})
</script>
</body>
</html>