aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/window/opener/index.html
blob: e7ddb3e8c12fbdc944692067c3d629eae08d41db (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
---
title: Window.opener
slug: Web/API/Window/opener
translation_of: Web/API/Window/opener
---
<div>{{APIRef}}</div>

<h2 id="Summary" name="Summary">概要</h2>

<p>回傳一個開啟目前視窗(window)之視窗的參考(reference)。</p>

<h2 id="Syntax" name="Syntax">語法</h2>

<pre class="syntaxbox"><var>objRef</var> = window.opener;
</pre>

<h2 id="Example" name="Example">範例</h2>

<pre class="brush:js">if (window.opener != indexWin) {
  referToTop(window.opener);
}
</pre>

<h2 id="Notes" name="Notes">備註</h2>

<p>當一個視窗是由另一個視窗所開啟(使用 {{domxref("Window.open")}} 或一個帶有 <code><a href="/zh-TW/docs/Web/HTML/Element/a#attr-target">target</a></code> 屬性設定的連結),被開啟的這個視窗會於 <strong>window.opener</strong> 保留開啟它的第一個視窗之參考。假如目前的視窗沒有開啟它的視窗,則會回傳 NULL。</p>

<p>Windows Phone 瀏覽器不支援 <code>window.opener</code>(測試版本為 Microsoft Edge 25.10586.36.0)。若 <code>window.opener</code> 為不同的安全區域(security zone),則 IE 也不支援此屬性。</p>

<p><a href="https://caniuse.com/#search=noopener">某些瀏覽器</a>中,在發起連結的標籤中加入 <code>rel="noopener"</code> 屬性,可以阻止設定 <code>window.opener</code> 視窗參考。</p>