Skip to content

Instantly share code, notes, and snippets.

@brianonn
Created December 19, 2017 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianonn/1561949f6dbd090dd032bdf18a12218d to your computer and use it in GitHub Desktop.
Save brianonn/1561949f6dbd090dd032bdf18a12218d to your computer and use it in GitHub Desktop.
test loading XHR content into an iframe
<div id='body'>
<h1>this is a header</h1>
<iframe id='iframe' />
</div>
<p id='responseText'>
</p>
var website = 'https://notpibsb0j.execute-api.us-east-2.amazonaws.com/Prod/';
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
console.log(xhttp.responseText);
var iframe= document.getElementById('iframe').contentWindow.document
iframe.open();
iframe.write(xhttp.responseText);
iframe.write('<p><strong>Test from Brian<strong></p>')
iframe.close();
$('#iframe').contents().find('body').append('<p>Test</p>');
}
};
setTimeout( () => {
xhttp.open("GET", website, true);
xhttp.send();
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment