6

I have a html page with an IFrame linking towards a text file, my html page's body is set to black, and the default color of the IFrame txt is black, so I cannot see my text :/ I would like to know how to change the text color, thanks. zeokila

<iframe src="http://wordpress.org/extend/plugins/about/readme.txt" width="470" frameborder="0" marginheight="0" marginwidth="0" style="overflow-x:hidden"></iframe> 
Alexandre Hitchcox
  • 2,704
  • 5
  • 22
  • 33
  • possible duplicate of [How to apply CSS to iFrame?](http://stackoverflow.com/questions/217776/how-to-apply-css-to-iframe) – John Conde Apr 22 '12 at 19:11
  • Not a dup. This is a text file with `.txt` extension. – Teemu Apr 22 '12 at 19:20
  • try importing the file as an `object` – hjpotter92 Apr 22 '12 at 19:21
  • This might be a stupid question, but how can you set a black background for the `IFRAME`, if there is txt file loaded? By default it is white. – Teemu Apr 22 '12 at 19:34
  • The default background color for the IFrame with .txt files is the default body background color, so if you set your body blue, and put an IFrame containing a .txt file, it would be blue – Alexandre Hitchcox Apr 22 '12 at 19:41
  • 2
    Good question. Upvoting. And who was the joker who wants to close this as "not a real question"? – Mr Lister Apr 22 '12 at 20:26

1 Answers1

4

This makes the trick at least in FF, IE and Opera.

document.getElementById('your_iframe_id').contentWindow.document.body.style.color='white';

In Chrome you can only change IFRAMEs background color:

document.getElementById('your_iframe_id').style.background='white';

And for change background color in IE:

document.getElementById('your_iframe_id').contentWindow.document.body.style.backgroundColor='yellow';

Then there is a big but... those expressions including contentWindow, work only, if the iframe and the host page are in the same domain.

(It is IE only having that white background by default)

Teemu
  • 22,918
  • 7
  • 53
  • 106