Applying background to Iframe [IE / Firefox /Safari / Opera

August 2, 2007

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>

<style>
#subscribe{
background:#ff0000;

}
</style>
<SCRIPT LANGUAGE=”JavaScript”>
function change_background() {
var iframeDoc;
if (window.frames && window.frames.subscribe && (iframeDoc = window.frames.subscribe.document)) {
// now use iframeDoc here
iframeDoc.body.style.backgroundColor=’red’;
//alert(iframeDoc.body.style.backgroundColor);
}

}
</SCRIPT>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body onLoad=”change_background();”>
<iframe src=”test1.html” id=”subscribe” name=”subscribe” scrolling=”no” frameborder=”0″></iframe>
</body>

</html>

Entry Filed under: Javascript. .

1 Comment Add your own

  • 1. Daniel Tome  |  July 30, 2008 at 3:07 am

    Hi,

    This will only work on iframes that are under the same domain.

    cheers,

    Reply

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Spam Blocked

Flickr Photos

Freeze

*

Cabo Negro

More Photos

Blogroll

Recent Posts

Recent Comments

Brightshore Miami on Convert em,px,pt and % in…
zolofth on Mozilla Addons and IE Addons f…
xx on validating textarea using…
jafar on Top 50 Govt Engineering C…
jafar on Top 50 Govt Engineering C…

Pages

Top Clicks

Top Posts

Blog Stats