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,开发者_Python百科 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?
"www.mysite.com" != "mysite.com"
cross frame/window communication needs to be on the same protocol+hostname+port
As Nick noted, the issue is a domain mismatch. If you're on the same domain, you can do this:
- Open your web console on the page you'll load in the iframe.
- Enter
document.domain
- Make sure
document.domain
on the page containing the iframe is set to the same value.
精彩评论