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.
This commit is contained in:
David Négrier 2021-06-28 11:51:13 +02:00
parent 63d4c99d15
commit 330a795fee

View File

@ -1,22 +1,31 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="http://play.workadventure.localhost/iframe_api.js"></script>
<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> </head>
<body> <body>
<button id="sendchat">Send chat message</button> <button id="sendchat">Send chat message</button>
<script> <script>
document.getElementById('sendchat').onclick = () => { document.getElementById('sendchat').onclick = () => {
WA.sendChatMessage('Hello world!', 'Mr ROBOT'); WA.chat.sendChatMessage('Hello world!', 'Mr ROBOT');
} }
</script> </script>
<div id="chatSent"></div> <div id="chatSent"></div>
<script> <script>
WA.onChatMessage((message => { window.addEventListener('load', () => {
const chatDiv = document.createElement('p'); WA.chat.onChatMessage((message => {
chatDiv.innerText = message; const chatDiv = document.createElement('p');
document.getElementById('chatSent').append(chatDiv); chatDiv.innerText = message;
})); document.getElementById('chatSent').append(chatDiv);
}));
})
</script> </script>
</body> </body>
</html> </html>