FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

CSS styling iframe page

 


wangbin218200
I have an affiliate shop with order page loading in iframe from another domain. I'm looking for a way to change CSS style of this iframe-page.

mysite.com/buy.html looks like this:

Code:
<HTML>
<HEAD>

<script type="text/javascript">
function styleIFrame()
{ document.frames['orderframe'].document.body.style.backgroundColor="green";
}
</script>

</HEAD>
<body onload="styleIFrame();">

<iframe id="orderframe" name="orderframe" src="https://ANOTHERdomain.com/order.html"></iframe>

</body>
</html>IE 6 throws JS-error: "Access is denied". I think this is because domains differ or because of httpS of iframe src. Are there any workarounds? Thanks.
LukeakaDanish
Could you put your code inside
Code:
[code][/code]
tags?

Its certainly got nothing to do with the https thing - ive experimented a bit with this and even when i try to change the background color of, for example, google.com both IE6 & 7, opera and firefox just output "green" to the screen, overwriting the normal content.

Firefox initially makes the page green for a split second, before overwriting the content. Because of this, pressing back, after the content is gone, brings up the page with the new background color.



ANYWAY...seen as that didnt really solve anything, here's my solution:


Write a function in your page on the other domain, and then call that function!

If thats not an option, i suggest trying to refer to the body element in another way - maybe this:

Code:
document.getElementById('orderframe').document.getElementsByTagName('body').item(0).style.backgroundColor = 'green'


or even:

Code:
orderframe.document.getElementsByTagName('body').item(0).style.backgroundColor = 'green'
Kaneda
The "Access Denied" error is indeed due to differing domains - it's a security measure to avoid cross server scripting (Example of what would be possible otherwise: you'd be able to have a "smart" link to, say, GMail on your site, which really opened GMail in an IFRAME, then added a script to monitor what the user typed as username and password, and send this information to YOUR server, through XMLHttpRequest - without the user even knowing (since GMail still worked for him).

There's no way to do ANYTHING to the DOM inside an IFRAME with a page from another domain - if there is, it's a browser flaw. No way of refering to the contents of the frame will work.

One way (but won't do much good in this case, I'd think) is to make a PHP/ASP/ASP.NET/whatever script on your own server, which simply relays the response from the remote server. That way, the response really comes from your own server, and you can modify the DOM - including CSS.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.