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
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed



1.
Daniel Tome | July 30, 2008 at 3:07 am
Hi,
This will only work on iframes that are under the same domain.
cheers,