Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save tonyfast/0b4aab02bd3c5427a702 to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/0b4aab02bd3c5427a702 to your computer and use it in GitHub Desktop.
Dynamically create an iframe using a string
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
var head = 'data:text/html;charset=utf-8,', // html headers
src = '<body><h1>This is a the page source</h1><p>Here is the text body.</p></body>'; //html content
$(document).ready( function(){
$('<iframe/>').appendTo( 'body' )
.attr( 'src' , head + src );
return null
});
</script>
</head>
<body></body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment