I have a page ,page1.html that loads page2.html via an iframe . I need to change the body color of the iframe page (page2.html) to override the CSS style that's loaded on page2.html. (both pages are on same domain). How can that be updated via Javascript ?
+2
A:
A bit of googling turn up this:
It suggests window.frames[iframeName].document should work.
Duke of Muppets
2009-02-27 19:49:32
A:
Since both pages lives on the same domain it should be easy.
Try this,
var changeIFrameBodyColor = function()
{
var iFrame = document.getElementById('iFrame');
var iFrameBody;
if ( iFrame.contentDocument )
{ // DOM
var iFrameBody = iFrame.contentDocument.getElementdByTagName('body')[0];
}
else if ( iFrame.contentWindow )
{ // IE
var iFrameBody = iFrame.contentWindow.document.getElementdByTagName('body')[0];
}
iFrameBody.style.color = '#ff0000';
}
<a href="javascript:;" onclick="changeIFrameBodyColor()">Change Color</a>
<iframe id="iFrame" src="page2.html" ../>
tan
2009-02-27 20:03:57
Make that getElement<b>s</b>ByTagName
KooiInc
2009-02-27 22:23:06