Använder nu postMessage för att få över variabler till iframe

This commit is contained in:
2024-07-30 23:47:16 +02:00
parent a12c11c058
commit 7bc8a129c6
+14 -2
View File
@@ -15,15 +15,27 @@
srcdoc="{{ client_content }}">
</iframe>
<script>
<!-- <script>
// Extract apiEndpoint for use in your frontend code...
const apiEndpoint = '{{ api_endpoint }}'; // Templating syntax (Jinja2)
const useModel = '{{ use_model }}'; // Templating syntax (Jinja2)
// Tell the iframe about the apiEndpoing
// Tell the iframe about the apiEndpoint
document.getElementById('client-frame').contentWindow.apiEndpoint = apiEndpoint;
document.getElementById('client-frame').contentWindow.useModel = useModel;
console.log("index.html - API Endpoint: ", apiEndpoint);
console.log("index.html - use model: ", useModel);
</script> -->
<script>
// Extract apiEndpoint for use in frontend.js
const apiEndpoint = '{{ api_endpoint }}'; // Templating syntax (Jinja2)
const useModel = '{{ use_model }}'; // Templating syntax (Jinja2)
window.addEventListener('load', function() {
const clientFrame = document.getElementById('client-frame').contentWindow;
clientFrame.postMessage({ apiEndpoint, useModel }, '*'); // Send the data to the iframe
});
console.log("index.html - API Endpoint: ", apiEndpoint);
console.log("index.html - use model: ", useModel);
</script>
<!-- Responsive scaling and some padding -->