简体   繁体   中英

Permission denied for iframe with source on same domain - Apache vhost cfg issue?

I'm using javascript to manipulate an iframe on a page which loads content from the same domain as the page doing the manipulation. In fact in the iframe src I am using a relative path like this:

<iframe id="myiframe" src="/foo/bar.html" .../>

The page displays in the iframe without problems, but when I try to access the iframe using javascript, I get this error:

Permission denied for http://mysite.com to get property Window.document from http://www.mysite.com .

I know http://www.mysite.com and http://mysite.com are considered different domains regardless of where they physically exist, but I've never configured anything to use the www. subdomain. So I have no idea where the www part is coming from. My best guess is that I need to change something in my vhosts configuration. I'm using Apache 2 and I have a very simple virtual host config file:

<VirtualHost *>
    ServerName mysite.com
    DocumentRoot /path/to/mysite.com/www
</VirtualHost>

Any ideas?

As Nick noted , the issue is a domain mismatch. If you're on the same domain, you can do this:

  1. Open your web console on the page you'll load in the iframe.
  2. Enter document.domain
  3. Make sure document.domain on the page containing the iframe is set to the same value.

"www.mysite.com" != "mysite.com"

cross frame/window communication needs to be on the same protocol+hostname+port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM