aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/navigator/share/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ja/web/api/navigator/share/index.html')
-rw-r--r--files/ja/web/api/navigator/share/index.html94
1 files changed, 94 insertions, 0 deletions
diff --git a/files/ja/web/api/navigator/share/index.html b/files/ja/web/api/navigator/share/index.html
new file mode 100644
index 0000000000..63d289c4e9
--- /dev/null
+++ b/files/ja/web/api/navigator/share/index.html
@@ -0,0 +1,94 @@
+---
+title: Navigator.share()
+slug: Web/API/Navigator/share
+tags:
+ - Method
+ - Navigator
+ - Reference
+ - Share
+ - Web
+ - メソッド
+translation_of: Web/API/Navigator/share
+---
+<div>{{APIRef("HTML DOM")}}{{securecontext_header}}</div>
+
+<p><strong><code>Navigator.share()</code></strong> メソッドは、 Web Share API の一部としてのネイティブの共有メカニズムを呼び出します。</p>
+
+<h2 id="Syntax" name="Syntax">構文</h2>
+
+<pre class="syntaxbox">var sharePromise = navigator.share(<var>data</var>);
+</pre>
+
+<h3 id="Parameters" name="Parameters">引数</h3>
+
+<dl>
+ <dt><code><var>data</var></code></dt>
+ <dd>シェアするデータを含むオブジェクトです。以下のフィールドのうち少なくとも一つを指定しなければなりません。利用可能なオプションは下記のとおりです。</dd>
+</dl>
+
+<ul>
+ <li><code>url</code>: シェアする URL を表す {{domxref("USVString")}}。</li>
+ <li><code>text</code>: シェアするテキストを表す {{domxref("USVString")}}。</li>
+ <li><code>title</code>: シェアするタイトルを表す {{domxref("USVString")}}。</li>
+</ul>
+
+<dl>
+</dl>
+
+<h3 id="Return_value" name="Return_value">返値</h3>
+
+<p>ユーザーがシェア操作を完了させたとき (ふつうはユーザーがシェア先のアプリケーションを選択したとき) に解決する {{domxref("Promise")}} です。引数 <var>data</var> が正しく指定されなかった場合は直ちに拒否され、ユーザーがシェアをキャンセルした場合も拒否されます。</p>
+
+<h2 id="Examples" name="Examples">例</h2>
+
+<p><a href="https://mdn.github.io/dom-examples/web-share/">ウェブシェアテスト</a> (<a href="https://github.com/mdn/dom-examples/blob/master/web-share/index.html">ソースコードを参照</a>) では、ボタンが一つあり、クリックすると Web Share API を呼び出して MDN の URL をシェアします。 JavaScript は以下のようになります。</p>
+
+<pre class="brush: js">const shareData = {
+ title: 'MDN',
+ text: 'MDN でウェブ開発を学びましょう。',
+ url: 'https://developer.mozilla.org',
+}
+
+const btn = document.querySelector('button');
+const resultPara = document.querySelector('.result');
+
+// Must be triggered some kind of "user activation"
+btn.addEventListener('click', async () =&gt; {
+ try {
+ await navigator.share(shareData)
+ resultPara.textContent = 'MDN shared successfully'
+ } catch(err) {
+ resultPara.textContent = 'Error: ' + e
+ }
+});</pre>
+
+<h2 id="Specifications" name="Specifications">仕様書</h2>
+
+<table>
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ <th scope="col">状態</th>
+ <th scope="col">備考</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('Web Share API','#share-method','share()')}}</td>
+ <td>{{Spec2('Web Share API')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
+
+<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
+
+<p>{{Compat("api.Navigator.share")}}</p>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li>{{domxref('navigator.canShare', 'navigator.canShare()')}}</li>
+</ul>