aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/history/replacestate/index.md
diff options
context:
space:
mode:
Diffstat (limited to 'files/ja/web/api/history/replacestate/index.md')
-rw-r--r--files/ja/web/api/history/replacestate/index.md73
1 files changed, 73 insertions, 0 deletions
diff --git a/files/ja/web/api/history/replacestate/index.md b/files/ja/web/api/history/replacestate/index.md
new file mode 100644
index 0000000000..c06e22398e
--- /dev/null
+++ b/files/ja/web/api/history/replacestate/index.md
@@ -0,0 +1,73 @@
+---
+title: History.replaceState()
+slug: Web/API/History/replaceState
+tags:
+ - API
+ - HTML DOM
+ - History
+ - History API
+ - Method
+ - Reference
+translation_of: Web/API/History/replaceState
+---
+<div>{{APIRef("History API")}}</div>
+
+<p><strong><code>History.replaceState()</code></strong> メソッドは、現在の履歴を編集し、メソッドに渡された <code>stateObj</code>、<code>title</code>、<code>URL</code> パラメータによって置き換えます。このメソッドは、ユーザーのアクションに応じて現在の履歴エントリの state オブジェクトや URL を更新したい場合に特に便利です。</p>
+
+<h2 id="Syntax" name="Syntax">構文</h2>
+
+<pre class="syntaxbox notranslate">history.replaceState(<em>stateObj</em>, <em>title</em>, [<em>url</em>])</pre>
+
+<h3 id="Parameters" name="Parameters">パラメータ</h3>
+
+<dl>
+ <dt><code>stateObj</code></dt>
+ <dd>state オブジェクトは、replaceState メソッドに渡された履歴エントリに関連付けられた JavaScript オブジェクトです。state オブジェクトは null を指定することができます。</dd>
+ <dt><code>title</code></dt>
+ <dd><a href="https://github.com/whatwg/html/issues/2174">ブラウザーの多くは現在このパラメータを無視します</a>、しかしながら将来は使うようになるかもしれません。ここに空の文字列を渡すことは、将来メソッドが変更されることになっても安全です。あるいは、状態を表す短いタイトルを渡すこともできます。</dd>
+ <dt><code>url</code> {{optional_inline}}</dt>
+ <dd>履歴エントリの URL です。新しい URL は現在の URL と同じオリジンでなければなりません。もしそうでないと、replaceState から例外が投げられます。</dd>
+</dl>
+
+<h2 id="Examples" name="Examples">使用例</h2>
+
+<p>https://www.mozilla.org/foo.html が以下の JavaScript を実行したとします:</p>
+
+<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">const </span>stateObj <span class="operator token">=</span> <span class="punctuation token">{</span> foo<span class="punctuation token">:</span> '<span class="string token">bar'</span> <span class="punctuation token">}</span><span class="punctuation token">;</span>
+history<span class="punctuation token">.</span><span class="function token">pushState</span><span class="punctuation token">(</span>stateObj<span class="punctuation token">,</span> <span class="string token">''</span><span class="punctuation token">,</span> '<span class="string token">bar.html'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
+
+<p>上記の 2行の説明は、「<a href="/ja/docs/Web/API/History_API/Working_with_the_History_API">History API を取り扱う</a>」の記事の「<a href="/ja/docs/Web/API/History_API/Working_with_the_History_API#pushState_%E3%81%AE%E4%BE%8B"><code>pushState()</code> の例</a>」にあります。次に、https://www.mozilla.org/bar.html が以下の JavaScript を実行したとします:</p>
+
+<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">history<span class="punctuation token">.</span><span class="function token">replaceState</span><span class="punctuation token">(</span>stateObj<span class="punctuation token">,</span> <span class="string token">''</span><span class="punctuation token">,</span> '<span class="string token">bar2.html'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
+
+<p>これにより、URL バーに https://www.mozilla.org/bar2.html が表示されるようになりますが、ブラウザーが <code>bar2.html</code> を読み込んだり、<code>bar2.html</code> が存在するかどうかを確認したりすることはありません。</p>
+
+<p>ユーザーが https://www.microsoft.com に移動し、戻るボタンをクリックしたとします。この時点で、URL バーには https://www.mozilla.org/bar2.html が表示されます。ユーザーがもう一度「戻る」ボタンをクリックすると、URL バーには https://www.mozilla.org/foo.html が表示され、bar.html は完全にバイパスされます。</p>
+
+<h2 id="Specifications" name="Specifications">仕様</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">仕様書</th>
+ <th scope="col">策定状況</th>
+ <th scope="col">コメント</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("HTML WHATWG", "history.html#dom-history-replacestate", "History.replaceState()")}}</td>
+ <td>{{Spec2("HTML WHATWG")}}</td>
+ <td>No change from {{SpecName("HTML5 W3C")}}.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName("HTML5 W3C", "history.html#dom-history-replacestate", "History.replaceState()")}}</td>
+ <td>{{Spec2("HTML5 W3C")}}</td>
+ <td>初期定義</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</h2>
+
+
+
+<p>{{Compat("api.History.replaceState")}}</p>