aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/navigator/registerprotocolhandler
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/api/navigator/registerprotocolhandler
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/ja/web/api/navigator/registerprotocolhandler')
-rw-r--r--files/ja/web/api/navigator/registerprotocolhandler/index.html150
-rw-r--r--files/ja/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html132
2 files changed, 282 insertions, 0 deletions
diff --git a/files/ja/web/api/navigator/registerprotocolhandler/index.html b/files/ja/web/api/navigator/registerprotocolhandler/index.html
new file mode 100644
index 0000000000..1eda18c297
--- /dev/null
+++ b/files/ja/web/api/navigator/registerprotocolhandler/index.html
@@ -0,0 +1,150 @@
+---
+title: Navigator.registerProtocolHandler()
+slug: Web/API/Navigator/registerProtocolHandler
+tags:
+ - API
+ - DOM
+ - DOM Reference
+ - Method
+ - Navigator
+ - Reference
+ - Web-Based Protocol Handlers
+ - registerProtocolHandler
+translation_of: Web/API/Navigator/registerProtocolHandler
+---
+<div>{{APIRef("HTML DOM")}}{{securecontext_header}}</div>
+
+<p><span class="seoSummary"><strong>{{domxref("Navigator")}}</strong> の <code><strong>registerProtocolHandler()</strong></code> メソッドは、ウェブサイトが特定の URL スキーム (別名プロトコル) を開いたり処理したりする能力を登録することを可能にします。</span></p>
+
+<p>例えば、この API はウェブメールサイトを <code>mailto:</code> の URL で開かせたり、 <abbr title="Voice over Internet Protocol, also called IP telephony">VoIP</abbr> サイトを <code>tel:</code> の URL で開かせたりします。</p>
+
+<h2 id="Syntax" name="Syntax">構文</h2>
+
+<pre class="syntaxbox notranslate">navigator.registerProtocolHandler(<var>scheme</var>, <var>url</var>, <var>title</var>);
+</pre>
+
+<div class="note"><strong>注:</strong> 最近になって <code>navigator.registerProtocolHandler(<var>scheme</var>, <var>url</var>)</code> と更新されましたが、こちらに対応しているブラウザーは今のところありませx。</div>
+
+<h3 id="Parameters" name="Parameters">引数</h3>
+
+<dl>
+ <dt><code><var>scheme</var></code></dt>
+ <dd>サイトが処理したいプロトコルを指定する文字列。例えば、 <code>"sms"</code> スキームを渡すことで、SMS テキストメッセージリンクを扱うように登録することができます。</dd>
+ <dt><code><var>url</var></code></dt>
+ <dd>ハンドラーの URL を指定する文字列。この文字列には、処理される文書の URL をエスケープした者で置き換えられるプレイスホルダー "%s" を含めてください。この URL は本物の URL のほか、電話番号、メールアドレスなどにすることもできます。
+ <div class="note"><strong>注:</strong> ハンドラー URL のスキームは <code>https</code> でなければなりません。ブラウザーによってはセキュリティのため、 HTTPS の URL であることを求めるため、<em>そうするべきです</em>。</div>
+ </dd>
+ <dt><code><var>title</var></code> {{Obsolete_Inline}}</dt>
+ <dd>ハンドラーを表す人間が読めるタイトル文字列です。これは、「このサイトで [スキーム] リンクを扱うことを許可しますか?」というプロンプトや、ブラウザーの設定で登録されたハンドラーを一覧表示するなどの形で<strong>ユーザーに表示されます</strong>。
+ <div class="note"><strong>注:</strong> タイトルはなりすましの懸念から仕様から削除されましたが、現在のすべてのブラウザーでは<strong>まだ必要とされています</strong>。更新された仕様に対応しているブラウザーはほとんどの場合、下位互換性があり、まだ受け付けている可能性が高いので、<strong>常にタイトルを設定</strong>しておくことをお勧めします (ただし、使用はしません)。</div>
+ </dd>
+</dl>
+
+<h3 id="Exceptions" name="Exceptions">例外</h3>
+
+<dl>
+ <dt>{{Exception("SecurityError")}}</dt>
+ <dd>ユーザーエージェントが登録をブロックしました。以下のような場合に起こる可能性があります。</dd>
+</dl>
+
+<ul>
+ <li>ブラウザーが独自に処理するスキーム (<code>https:</code>, <code>about:</code>, など) など、登録されているスキーム (プロトコル) が無効です。</li>
+ <li>ハンドラーの URL の{{Glossary("origin", "オリジン")}}が、本 API を呼び出すページのオリジンと一致しない。</li>
+ <li>ブラウザーが、この関数を安全なコンテキストから呼び出す必要がある。</li>
+ <li>ブラウザーがハンドラーの URL が HTTPS 以上であることを要求している。</li>
+</ul>
+
+<dl>
+ <dt>{{Exception("SyntaxError")}}</dt>
+ <dd><code>%s</code> が指定されたハンドラー URL に含まれていない。</dd>
+</dl>
+
+<h2 id="Permitted_schemes" name="Permitted_schemes">許可されたスキーム</h2>
+
+<p>セキュリティ上の理由により <code>registerProtocolHandler()</code> は登録可能なスキームに制限を設けています。</p>
+
+<p><strong>カスタムスキーム</strong>は次のような場合に登録されます。</p>
+
+<ul>
+ <li>カスタムスキームの名前が <code>web+</code> で始まる</li>
+ <li>カスタムスキームの名前が <code>web+</code> 接頭辞の後に1文字以上ある</li>
+ <li>カスタムスキームの名前に小文字の ASCII 文字のみが含まれている</li>
+</ul>
+
+<p>例えば下の {{anch("Example", "例")}} で使われている <code>web+burger</code> などが挙げられます。</p>
+
+<p>もしくは、以下のホワイトリストに挙げられているスキームでなければなりません。</p>
+
+<div class="threecolumns">
+<ul>
+ <li><code>bitcoin</code></li>
+ <li><code>geo</code></li>
+ <li><code>im</code></li>
+ <li><code>irc</code></li>
+ <li><code>ircs</code></li>
+ <li><code>magnet</code></li>
+ <li><code>mailto</code></li>
+ <li><code>mms</code></li>
+ <li><code>news</code></li>
+ <li><code>nntp</code></li>
+ <li><code>openpgp4fpr</code></li>
+ <li><code>sip</code></li>
+ <li><code>sms</code></li>
+ <li><code>smsto</code></li>
+ <li><code>ssh</code></li>
+ <li><code>tel</code></li>
+ <li><code>urn</code></li>
+ <li><code>webcal</code></li>
+ <li><code>wtai</code></li>
+ <li><code>xmpp</code></li>
+</ul>
+</div>
+
+<h2 id="Example" name="Example">例</h2>
+
+<p>ウェブアプリケーションが <code>burgers.example.com</code> にある場合、次のようにして <code>web+burger:</code> リンクを処理するプロトコルハンドラーを登録できます:</p>
+
+<pre class="brush: js notranslate">navigator.registerProtocolHandler("web+burger",
+ "https://burgers.example.com/?burger=%s",
+ "Burger handler");
+</pre>
+
+<p>これは、 <code>web+burger:</code> リンクがアクセスしたバーガーの URL を <code>%s</code> プレースホルダーに挿入し、ユーザーをサイトに誘導するハンドラーを作成します。</p>
+
+<p>このスクリプトはハンドラーの URL と同じオリジン (すなわち、 <code>https://burgers.example.com</code> にあるページのいずれか) から実行する必要があり、ハンドラーの URL は <code>http</code> または <code>https</code> である必要があります。</p>
+
+<p>あなたのコードがプロトコルハンドラーを登録しようとしていることはユーザーに通知され、ユーザーは登録を許可するかどうか決めることができます。以下のスクリーンショットは <code>google.co.uk</code> での例です。</p>
+
+<p><img alt="A browser notification reads “Add Burger handler (www.google.co.uk) as an application for burger links?”, and offers an “Add Application” button and a close to ignore the handler request." src="https://mdn.mozillademos.org/files/9683/protocolregister.png"></p>
+
+<h2 id="Specifications" name="Specifications">仕様書</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ <th scope="col">状態</th>
+ <th scope="col">備考</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'system-state.html#custom-handlers', 'registerProtocolHandler()')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>Living standard</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.registerProtocolHandler")}}</p>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li><a href="/ja/docs/Web-based_protocol_handlers">ウェブベースのプロトコルハンドラー</a></li>
+ <li>Mozilla Webdev の <a href="http://blog.mozilla.com/webdev/2010/07/26/registerprotocolhandler-enhancing-the-federated-web/">RegisterProtocolHandler Enhancing the Federated Web</a></li>
+</ul>
diff --git a/files/ja/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html b/files/ja/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html
new file mode 100644
index 0000000000..e131010da8
--- /dev/null
+++ b/files/ja/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html
@@ -0,0 +1,132 @@
+---
+title: ウェブベースのプロトコルハンドラー
+slug: Web/API/Navigator/registerProtocolHandler/Web-based_protocol_handlers
+tags:
+ - Advanced
+ - HTML5
+ - Web-Based Protocol Handlers
+translation_of: Web/API/Navigator/registerProtocolHandler/Web-based_protocol_handlers
+---
+<div>{{Fx_minversion_header(3)}}</div>
+
+<h2 id="Background" name="Background">背景</h2>
+
+<p>ウェブページで <code>http</code> ではないプロトコルを使用したリソースへのリンクを見つけることがよくあります。例えば、 <code>mailto:</code> プロトコルです。</p>
+
+<div style="overflow: hidden;">
+<pre class="brush:html">&lt;a href="mailto:webmaster@example.com"&gt;ウェブマスター&lt;/a&gt;</pre>
+</div>
+
+<p>ウェブ制作者は、ユーザーがウェブページから直接 E メールを送るのに便利な方法を提供したいときに、 <code>mailto:</code> リンクを用いることができます。リンクがアクティブ化されたとき、ブラウザは、E メールを扱うための標準のデスクトップアプリケーションを起動させるはずです。これは、<em>デスクトップベース</em> プロトコルハンドラーと考えることができます。</p>
+
+<p>ウェブベースプロトコルハンドラーは、ウェブベースアプリーケーションもその処理に追加することを可能にします。これはアプリケーションをウェブに移行させるうえでますます重要になってきています。実際、 <code>mailto</code> リンクを処理できる可能性がある多くのウェブベースの E メールを扱うアプリケーションが存在しています。</p>
+
+<h2 id="Registering" name="Registering">登録</h2>
+
+<p>ウェブアプリケーションをプロトコルハンドラーとして設定するのは、難しい処理ではありません。基本的に、ウェブアプリケーションは自身を指定したプロトコルのための可能なハンドラーとしてブラウザに登録するために <code><a href="/ja/docs/DOM/window.navigator.registerProtocolHandler">registerProtocolHandler()</a></code> を使用します。</p>
+
+<pre class="brush: js">navigator.registerProtocolHandler("web+burger",
+ "http://www.google.co.uk/?uri=%s",
+ "Burger handler");</pre>
+
+<p>ここでの引数は次の通りです。</p>
+
+<ul>
+ <li>プロトコル。</li>
+ <li>URL のテンプレート。"%s" は、リンクの <code>href</code> 属性の値に置換され、GET は置換後の URL に対して実行されます。</li>
+ <li>プロトコルハンドラーのためのユーザーにわかりやすい名前。</li>
+</ul>
+
+<p>ブラウザがこのコードを実行するとき、ユーザーにプロンプトを表示し、そのプロトコルのためのハンドラーとしてそのウェブアプリケーションを登録して良いかどうかの許可を求めるはずです。Firefox は、情報バーエリアに以下のプロンプトを表示します。</p>
+
+<p><img alt="" src="https://mdn.mozillademos.org/files/9683/protocolregister.png" style="display: block; height: 401px; margin: 0px auto; width: 700px;"></p>
+
+<div class="note"><strong>メモ:</strong> URL テンプレートが提供されるとき、登録する URL は登録が行われようとするウェブページと同じドメインである<strong>必要があります</strong>。異なるドメインであった場合は、登録は失敗します。 例えば <code>http://example.com/homepage.html</code> では <code>http://example.com/handle_mailto/%s</code> はプロトコルハンドラーとして登録可能ですが、 <code>http://example.<em><strong>org</strong></em>/handle_mailto/%s</code> はプロトコルハンドラーとして登録することはできません。</div>
+
+<p>同じプロトコルハンドラーを二回以上登録すると、そのプロトコルハンドラーが既に登録済みであることを示す別のポップアップが表示されます。従って、プロトコルハンドラーの登録を呼び出すのを防ぐために、以下のように既に登録済みであるかどうかを確認するのが良いでしょう。</p>
+
+<h3 id="Example" name="Example">例</h3>
+
+<pre class="brush: js">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
+&lt;html lang="ja"&gt;
+&lt;head&gt;
+ &lt;title&gt;ウェブプロトコルハンドラーサンプル - 登録&lt;/title&gt;
+ &lt;script type="text/javascript"&gt;
+ navigator.registerProtocolHandler("web+burger",
+ "http://www.google.co.uk/?uri=%s",
+ "Burger handler");
+ &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+ &lt;h1&gt;ウェブプロトコルハンドラーサンプル&lt;/h1&gt;
+ &lt;p&gt;このウェブページは、 &lt;code&gt;fake:&lt;/code&gt; プロトコルのためのウェブプロトコルハンドラーをインストールします。&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="Activating" name="Activating">有効化</h2>
+
+<p>登録すると、ユーザーが登録されたプロトコルを用いたリンクを有効化したときに、ブラウザはウェブアプリケーションが登録されたときに提供された URL へアクションを送るようになります。Firefox は、既定では、アクションを実行する前にユーザーにプロンプトを表示します。</p>
+
+<h3 id="Example_2" name="Example_2">例</h3>
+
+<pre class="brush: html">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
+&lt;html lang="ja"&gt;
+&lt;head&gt;
+ &lt;title&gt;ウェブプロトコルハンドラーサンプル - テスト&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+ &lt;p&gt;やあ、前に&lt;a href="web+burger:cheeseburger"&gt;これ&lt;/a&gt;を見たことある?&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="Handling" name="Handling">ハンドリング</h2>
+
+<p>次の段階は、アクションをハンドリング(実行)することです。ブラウザはアクティブ化されたリンクから <code>href</code> 属性の値を展開し、ハンドラー登録時に提供された URL テンプレートと結合し、その URL 上で HTTP GET を行います。ですから、上記の例では、ブラウザは、次の URL 上で GET を行います。</p>
+
+<pre>http://www.google.co.uk/?uri=web+burger:cheeseburger
+</pre>
+
+<p>サーバー側コードは、クエリ文字列パラメータを展開し、要求されたアクションを行います。</p>
+
+<div class="note"><strong>メモ:</strong> サーバー側コードには <code>href</code> 属性の値の <strong>完全</strong> な内容が渡されます。つまり、サーバー側コードは、そのデータからプロトコルを解釈しなければならないということです。</div>
+
+<h3 id="Example_3" name="Example_3">例</h3>
+
+<pre class="brush: php">&lt;?php
+$value = "";
+if ( isset ( $_GET["value"] ) ) {
+ $value = $_GET["value"];
+}
+?&gt;
+
+&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
+&lt;html lang="ja"&gt;
+&lt;head&gt;
+ &lt;title&gt;ウェブプロトコルハンドラーサンプル&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+ &lt;h1&gt;ウェブプロトコルハンドラーサンプル - ハンドラ&lt;/h1&gt;
+ &lt;p&gt;このウェブページは、 &lt;code&gt;web+burger:&lt;/code&gt; プロトコルアクションをハンドリングしたときに呼び出されます。次のデータが送られました。&lt;/p&gt;
+ &lt;textarea&gt;
+&lt;?php echo(htmlspecialchars($value, ENT_QUOTES, 'UTF-8')); ?&gt;
+ &lt;/textarea&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="References" name="References">仕様書</h2>
+
+<ul>
+ <li><a href="http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#custom-handlers">http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#custom-handlers</a></li>
+</ul>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li><a href="/ja/docs/DOM/window.navigator.registerContentHandler">window.navigator.registerContentHandler</a></li>
+ <li><a href="/ja/docs/XPCOM_Interface_Reference/nsIProtocolHandler">nsIProtocolHandler</a> (XUL のみ)</li>
+ <li><a class="external" href="http://blog.mozilla.com/webdev/2010/07/26/registerprotocolhandler-enhancing-the-federated-web/">RegisterProtocolHandler Enhancing the Federated Web</a> at Mozilla Webdev</li>
+ <li><a href="https://developers.google.com/web/updates/2011/06/Registering-a-custom-protocol-handler">Register a custom protocolHandler</a> at Google Developers.</li>
+</ul>