Include HTML with dynamic URL
feels like iframe but there is no extra frame

Search for a command to run...
feels like iframe but there is no extra frame

No comments yet. Be the first to comment.
Vibe Video, thoughts of video production in agentic world

demo with sample codes

Inspirations from old days

recursion, complexity, probabilitistic argument, algorithmic algorithm, experimentation on million level dataset

GCP Conversational Agents and CloudRun

Here is a solution to dynamically load any HTML into any HTML element that has a w3-include-html attribute.
w3-include-html to specify the URL of HTML to include.The solution is not authored by me. It was copied some where years back. I can not traceback the source now.
The solution:
<script>
function includeHTML() {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
elmnt.innerHTML = this.responseText;
}
if (this.status == 404) {
elmnt.innerHTML = "Page not found.";
}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/* Exit the function: */
return;
}
}
}
includeHTML();
</script>
Usage:
<div class="card">
<div class="card-content">
<span class="card-title orange-text">Correlation (As syncronised signals)</span>
<div w3-include-html="/report/{{task_instance_slug}}/table_corr_gradient.html"></div>
</div>
</div>
In my use case, the {{task_instance_slug}} is interpolated by Flask every time the user triggers one execution. The system generates a report that is composed of multiple standalone files. Some of those files are images which are straightforward to include in the report template. Some of those files are HTML files, generated by DataFrame.to_html() function. We apply the techniques above to include those HTMLs.
Rationale: