Skip to content
Snippets Groups Projects
includeHTML.ts 762 B
Newer Older
  • Learn to ignore specific revisions
  • let z:HTMLCollectionOf<HTMLElement> = <HTMLCollectionOf<HTMLElement>> document.getElementsByTagName("*");
    
    for (let i:number = 0; i < z.length; i++) {
        let element:HTMLElement = z[i];
        let externalFileURL:string = <string> element.getAttribute("includeHTML");
        if (externalFileURL != "") {
            let xhr:XMLHttpRequest = new XMLHttpRequest();
    
            xhr.onreadystatechange = function() {
                if (this.readyState == 4) {
                    if (this.status == 200) { element.innerHTML = this.responseText; }
                    if (this.status == 404) { element.innerHTML = "Page not found."; }
                    element.removeAttribute("includeHTML");
                }
            }
            xhr.open("GET", externalFileURL, true);
            xhr.send();
        }
    }