Click to See Complete Forum and Search --> : iframe


Platypus
06-03-2004, 07:35 PM
Hi

i was wondering if its posible to change page i'm loading in iframe using just javascript in the main page..


i have "main.html" and "frame.html" and in main.html i have this:

<iframe src="frame.html"...

i need to change background and text color/size on the page im loading in iframe.. i CAN'T change 'frame.html' so thats the problem..

i can use 'allowtransparency' in iframe tag and that would solve background problem but i still dont know if its posible to change text color and size

CrazyC115
06-03-2004, 10:29 PM
Hrm you could do something like this...

Script Code:

function changeIframeContents()
{
var oFrame = document.frames.my_iframe.document.body.style;

oFrame.backgroundColor = "#000000";
oFrame.color = "#FFFFFF";
oFrame.fontSize = "20pt";
}


Body Code:

<iframe src="frame.html" name="my_iframe"></iframe>
<a href="javascript: changeIframeContents();">Change Iframe Contents</a>


That will effectively change the inline styles using javascript and jss. It worked for me, hope it helps.

Platypus
06-04-2004, 02:44 AM
thanks but it doesnt work... maybe i forgot to add something.. you ca check it here:

http://www.geekstinkbreath.net/javaskrol/

Pittimann
06-04-2004, 02:50 AM
Hi!

You are missing an "r"

document.frames.ifejm1.document.body.style; =>
document.frames.ifrejm1.document.body.style

Cheers - Pit

Kor
06-04-2004, 02:53 AM
to manipulate objects or functions of the page in iframe, you may use top.frames[] reference:

top.frames['iframename'].object
top.frames['iframename'].a_function()

Your case, ex:

<script>
function changeBg(){
top.frames['my_iframe'].document.body.style.backgroundColor="#CCCCCC";
}
</script>
...

<a href="#" onclick="changeBg();return false">change bgcolor of the page in iframe</a>
<iframe src="frame.html" name="my_iframe"></iframe>
...

Platypus
06-04-2004, 02:59 AM
Originally posted by Pittimann
Hi!

You are missing an "r"

document.frames.ifejm1.document.body.style; =>
document.frames.ifrejm1.document.body.style

Cheers - Pit


thanks.. typical error for me :)

Pittimann
06-04-2004, 03:07 AM
Hi!

My typical error is: I saw your typo and did not look deeper. Like I posted it, it wouldn't work in Mozilla.

Kor's code is the one to be used (top.frames instead of document.frames).

Cheers - Pit

Kor
06-04-2004, 03:43 AM
...and , very important. For security reasons you can not manipulate objects of function from page in iframe if that page in is not on the same domain as the parent page (cross-domain referenece is thus imposible).