79124469

Date: 2024-10-25 06:28:05
Score: 1
Natty:
Report link

I would have preferred to use the iframe method, but when the page is doing cross-origin resource sharing, the frame.contentWindow does not work (see https://community.appfarm.io/t/make-iframe-automatically-adjust-height-according-to-the-contents/491/2 and https://stackoverflow.com/a/10636765/1919793).

I ended up using https://stackoverflow.com/a/10312824/1919793 to modify https://www.w3schools.com/howto/tryit.asp?filename=tryhow_html_include_1 to load the content into a parent div tag:

function includeHTML(src) {
    var scriptTag = document.getElementsByTagName('script');
    scriptTag = scriptTag[scriptTag.length - 1];
    var parentTag = scriptTag.parentNode;
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4) {
            if (this.status == 200) { parentTag.innerHTML = this.responseText; }
            if (this.status == 404) { parentTag.innerHTML = "Page not found."; }
        }
    }      
    xhttp.open("GET", src, true);
    xhttp.send();
}

and called it like so:

<script src="https://what-a-nice-url-that.is/include.js" onerror="document.write('Permission Denied')"></script>
<div><script>includeHTML('https://what-a-nice-url-that.is/index.html')</script></div>
<noscript>JavaScript Disabled</noscript>
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: theSparky