<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Dynamically Place Content of div in Iframe</h1>
<div id="postentry">
<style type="text/css">
html, body { background: red;}
</style>
<body><h1>>Bad Code2<h1>tstt<h3>Only the iframe should be red<h3>
</div>
<h2>Footer</h2>
<script type="text/javascript">
var messageContent = document.getElementById('postentry');
if (messageContent)
{
var htmlContent = messageContent.innerHTML;
messageContent.innerHTML = '';
var iFrame = document.createElement("iframe");
iFrame.setAttribute("id","ifhsf2gxvzw54vx");
iFrame.marginWidth = "0";
iFrame.frameBorder = "1";
iFrame.height = "500px";
iFrame.width = "100%";
iFrame.style.zIndex = "999";
var htmlPost = document.getElementById('postentry');
if (htmlPost)
{
htmlPost.appendChild(iFrame);
var displayFrame = this.document.getElementById("ifhsf2gxvzw54vx");
var doc = displayFrame.contentDocument;
if (doc == undefined || doc == null)
{
doc = displayFrame.contentWindow.document;
}
doc.open();
doc.write(htmlContent);
doc.close();
doc.body.leftMargin = "0px";
doc.body.rightMargin = "0px";
doc.body.topMargin = "0px";
doc.body.bottomMargin = "0px";
}
}
</script>
</body>
</html>
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE