Skip to content

Instantly share code, notes, and snippets.

@caot
Last active November 13, 2019 14:13
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 caot/fac3aa0480680d59780cbc4717810023 to your computer and use it in GitHub Desktop.
Save caot/fac3aa0480680d59780cbc4717810023 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="jquery.min.js"></script>
</head>
<body>
<iframe id="myFrame" style="height:180px;width:100%"></iframe>
<script>
var iframe = document.getElementsByTagName('iframe')[0];
iframe.src = 'about:blank';
function myFunction() {
// var iframe = document.getElementsByTagName('iframe')[0];
// iframe.src = 'about:blank';
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
var elmnt = iframe.contentWindow.document.getElementsByTagName("H1")[0];
console.log([elmnt, elmnt.innerText]);
};
$( document ).ready(function() {
myFunction();
});
const html = `
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
<div class="w3-col l6 w3-center">
XXXXX
<h1>HTML</h1>
YYYYY
</div>
</body>
</html>
`
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment