469,288 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

"Accsss is denied" when using iframe.contentWindow.document

Hi everybody,

My goal is to set the height of the iframe to fit its content. There
was an earlier posting which gave some useful insights.

http://groups.google.com/groups?hl=e...BIFrame%2Bsize

The key idea is

function getInnerHeight(iframe){
var d=iframe.contentWindow ?
iframe.contentWindow.document :
iframe.contentDocument;
var h=0;
if(d){
if(d.documentElement && d.compatMode &&
d.compatMode=="CSS1Compat")
h=d.documentElement.scrollHeight;
else if(d.body)
h=d.body.scrollHeight;
if(h) h+=getInsets(d);
} return (h||300)+"px"; //300 is a default value
}

<iframe src="javascript:top.writeSomeText()"
width="559"
onload="this.style.height=getInnerHeight(this)"></iframe>

It works perfectly if the src of iframe is some local content.
Unfortunately, if I put src="http://www.yahoo.com", the line
iframe.contentWindow.document returns "access is denied" error.

Do you have any idea how to solve this problem?

Thanks
Dom
Jul 23 '05 #1
5 21680
On 7 Sep 2004 11:22:04 -0700, Dominic <do****@hotmail.com> wrote:

[snip]
It works perfectly if the src of iframe is some local content.
Unfortunately, if I put src="http://www.yahoo.com", the line
iframe.contentWindow.document returns "access is denied" error.

Do you have any idea how to solve this problem?


Generally, it can't be. See the FAQ, specifically section 4.19, for more
information.

<URL:http://jibbering.com/faq/>

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Dominic wrote:
It works perfectly if the src of iframe is some local content.
Unfortunately, if I put src="http://www.yahoo.com", the line
iframe.contentWindow.document returns "access is denied" error.


It looks like an XSS thing -- there probably isn't a way around it. If
there is a way around it then the workaround will probably stop working
when you upgrade your browser.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Now Playing ~ ./keane/hopes_and_fears/08_sunshine.ogg

Jul 23 '05 #3
On 7 Sep 2004 11:22:04 -0700, Dominic <do****@hotmail.com> declared in
comp.lang.javascript,alt.html,microsoft.public.scr ipting.jscript:
It works perfectly if the src of iframe is some local content.
Unfortunately, if I put src="http://www.yahoo.com", the line
iframe.contentWindow.document returns "access is denied" error.

Do you have any idea how to solve this problem?


Stop trying to breach copyright.

--
Mark Parnell
http://www.clarkecomputers.com.au
"Never drink rum&coke whilst reading usenet" - rf 2004
Jul 23 '05 #4
Mark Parnell <we*******@clarkecomputers.com.au> wrote in message news:<1c*******************************@40tude.net >...
On 7 Sep 2004 11:22:04 -0700, Dominic <do****@hotmail.com> declared in
comp.lang.javascript,alt.html,microsoft.public.scr ipting.jscript:
It works perfectly if the src of iframe is some local content.
Unfortunately, if I put src="http://www.yahoo.com", the line
iframe.contentWindow.document returns "access is denied" error.

Do you have any idea how to solve this problem?


Stop trying to breach copyright.


I think there may be a misunderstanding. "http://www.yahoo.com" is
only used to illustrate the situation of getting some remote content.
The remote content may come from our server of another domain name, or
from our partner. I realize that this is a problem as long as the data
is not located at local server.

Hope it is clear. I'm sorry if my earlier posting leads to the
misunderstanding.

Dom
Jul 23 '05 #5
Dominic wrote:
It works perfectly if the src of iframe is some local content.
Unfortunately, if I put src="http://www.yahoo.com", the line
iframe.contentWindow.document returns "access is denied" error.


<http://groups.google.de/groups?as_q=Same+Origin+Policy&as_ugroup=comp.lang .javascript&scoring=d&filter=0>

Please stop crossposting.
PointedEars, F'up2 cljs
--
The truth is out there... and so are the bugs...
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Darren Lew | last post: by
reply views Thread by Michael Leithold, WWK | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.