# Cross-window communication
The "Same Origin" (same site) policy limits access of windows and frame to each other.
The idea is that if we have two windows open: one from `john-smith.com`, and another one is `gmail.com`, then we wouldn't want a script from `john-smith.com` to read our mail.
[cut]
## Same Origin [#same-origin]
Two URLs are said to have the "same origin" if they have the same protocol, domain and port.
These URLs all share the same origin:
- `http://site.com`
- `http://site.com/`
- `http://site.com/my/page.html`
These ones do not:
- http://www.site.com
(another domain: `www.` matters)
- http://site.org
(another domain: `.org` matters)
- https://site.com
(another protocol: `https`)
- http://site.com:8080
(another port: `8080`)
If we have a reference to another window (a popup or iframe), and that window comes from the same origin, then we can do everything with it.
If it comes from another origin, then we can only change its location. Please note: not *read* the location, but *modify* it, redirect it to another place. That's safe, because the URL may contain sensitive parameters, so reading it from another origin is prohibited, but changing is not.
Also such windows may exchange messages. Soon about that later.
````warn header="Exclusion: subdomains may be same-origin"
There's an important exclusion in the same-origin policy.
If windows share the same second-level domain, for instance `john.site.com`, `peter.site.com` and `site.com`, we can use JavaScript to assign to `document.domain` their common second-level domain `site.com`. Then these windows are treated as having the same origin.
In other words, all such documents (including the one from `site.com`) should have the code:
```js
document.domain = 'site.com';
```
Then they can interact without limitations.
That's only possible for pages with the same second-level domain.
````
## Accessing an iframe contents
An `