blob: 83090ee98fca1a8d6909e550047d47af2182635d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
---
title: Origin
slug: Glossary/源
translation_of: Glossary/Origin
---
<p>Web内容的源由用于访问它的{{Glossary("URL")}} 的方案(协议),主机(域名)和端口定义。只有当方案,主机和端口都匹配时,两个对象具有相同的起源。</p>
<p>某些操作仅限于同源内容,而可以使用 <a href="/zh-CN/docs/Glossary/CORS">CORS</a> 解除这个限制。</p>
<h2 id="同源的例子">同源的例子</h2>
<table class="standard-table">
<tbody>
<tr>
<td style="width: 50%;"><code>http://example.com/app1/index.html</code><br>
<code>http://example.com/app2/index.html</code></td>
<td style="width: 50%;">same origin because same scheme (<code>http</code>) and host (<code>example.com</code>)</td>
</tr>
<tr>
<td style="width: 50%;"><code>http://Example.com:80</code><br>
<code>http://example.com</code></td>
<td style="width: 50%;">same origin because a server delivers HTTP content through port 80 by default</td>
</tr>
</tbody>
</table>
<h2 id="不同源的例子">不同源的例子</h2>
<table class="standard-table">
<tbody>
<tr>
<td style="width: 50%;"><code>http://example.com/app1</code><br>
<code>https://example.com/app2</code></td>
<td>different schemes</td>
</tr>
<tr>
<td style="width: 50%;"><code>http://example.com</code><br>
<code>http://www.example.com</code><br>
<code>http://myapp.example.com</code></td>
<td style="width: 50%;">different hosts</td>
</tr>
<tr>
<td style="width: 50%;"><code>http://example.com</code><br>
<code>http://example.com:8080</code></td>
<td style="width: 50%;">different ports</td>
</tr>
</tbody>
</table>
<h2 id="了解更多">了解更多</h2>
<p>详细信息,请看<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Same_origin_policy_for_JavaScript" title="/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript">同源策略</a>。</p>
|