From e2bfd07c61275049960fea9c529dc32945b366f3 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sun, 13 Feb 2022 00:12:52 +0900 Subject: を変換準備 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/html/element/input/url/index.html | 188 ++++++++++++------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/files/ja/web/html/element/input/url/index.html b/files/ja/web/html/element/input/url/index.html index 892ddfd519..01de4d8888 100644 --- a/files/ja/web/html/element/input/url/index.html +++ b/files/ja/web/html/element/input/url/index.html @@ -2,37 +2,37 @@ title: slug: Web/HTML/Element/input/url tags: - - Element + - 要素 - Form Control - - Form Inputs - - Forms + - フォーム入力s + - フォーム - HTML - HTML Input Types - - HTML forms + - HTML フォーム - Input - - Input Type - - Reference + - 入力型 + - リファレンス - Text - URL - control translation_of: Web/HTML/Element/input/url --- -
{{HTMLRef("Input_types")}}
+{{HTMLRef("Input_types")}} -

{{HTMLElement("input")}} 要素の url 型は、ユーザーに URL を入力および編集させるために使用します。

+{{HTMLElement("input")}} 要素の `url` 型は、ユーザーに URL を入力および編集させるために使用します。 -
{{EmbedInteractiveExample("pages/tabbed/input-url.html", "tabbed-shorter")}}
+{{EmbedInteractiveExample("pages/tabbed/input-url.html", "tabbed-shorter")}} - + -

入力値はフォームの送信前に自動的に検証され、空欄または正しい形式の URL のどちらかであることが確認されます。 CSS の {{cssxref(":valid")}} および {{cssxref(":invalid")}} 擬似クラスが自動的に適用され、フィールド上の現在の値が妥当なメールアドレスであるかどうかを視覚的に示します。

+入力値はフォームの送信前に自動的に検証され、空欄または正しい形式の URL のどちらかであることが確認されます。 CSS の {{cssxref(":valid")}} および {{cssxref(":invalid")}} 擬似クラスが自動的に適用され、フィールド上の現在の値が妥当なメールアドレスであるかどうかを視覚的に示します。 -

url 型に対応していないブラウザーでは、 url 入力欄は標準の {{HTMLElement("input/text", "text")}} 入力欄で代替されます。

+`url` 型に対応していないブラウザーでは、 `url` 入力欄は標準の {{HTMLElement("input/text", "text")}} 入力欄で代替されます。 - + @@ -45,7 +45,7 @@ translation_of: Web/HTML/Element/input/url - + @@ -54,20 +54,20 @@ translation_of: Web/HTML/Element/input/url
{{anch("Value", "値")}}{{anch("値")}} URL を表す {{domxref("DOMString")}}、または空欄
IDL 属性list, value, selectionEnd, selectionDirection`list`, `value`, `selectionEnd`, `selectionDirection`
メソッド
-

+## 値 -

{{HTMLElement("input")}} 要素の {{htmlattrxref("value", "input")}} 属性は {{domxref("DOMString")}} で、自動的に URL の構文として検証されます。より具体的に言うと、検証を通る値の書式は下記の2通りがあります。

+{{HTMLElement("input")}} 要素の {{htmlattrxref("value", "input")}} 属性は {{domxref("DOMString")}} で、自動的に URL の構文として検証されます。より具体的に言うと、検証を通る値の書式は下記の2通りがあります。
  1. 空文字列 ("")。ユーザーが値を入力しないか、または値が削除されたことを表します。
  2. -
  3. 単一の正しい形式の絶対 URL。 URL が実在する必要はありませんが、少なくとも正しい書式です。簡単に言えば、 urlscheme://restofurl の形です。
  4. +
  5. 単一の正しい形式の絶対 URL。 URL が実在する必要はありませんが、少なくとも正しい書式です。簡単に言えば、 `urlscheme://restofurl` の形です。
-

{{anch("Validation", "検証")}}の節で、どのようなメールアドレスが正しい形式であると検証されるかの詳細を参照してください。

+{{anch("検証")}}の節で、どのようなメールアドレスが正しい形式であると検証されるかの詳細を参照してください。

追加の属性

-

型に関係なくすべての {{HTMLElement("input")}} 要素を操作する属性に加え、 url 型の入力欄は次の属性にも対応しています。

+型に関係なくすべての {{HTMLElement("input")}} 要素を操作する属性に加え、 `url` 型の入力欄は次の属性にも対応しています。 @@ -78,35 +78,35 @@ translation_of: Web/HTML/Element/input/url - + - + - + - + - + - + - + - + @@ -116,33 +116,33 @@ translation_of: Web/HTML/Element/input/url

{{htmlattrdef("maxlength")}}

-

ユーザーが url 入力欄に入力することができる (UTF-16 コード単位での) 最大文字数です。 0 以上の整数値である必要があります。 maxlength が指定されていないか、無効な値が指定されていると、 url 入力欄には最大文字数が設定されません。この値は minlength の値以上である必要もあります。

+ユーザーが `url` 入力欄に入力することができる (UTF-16 コード単位での) 最大文字数です。 0 以上の整数値である必要があります。 `maxlength` が指定されていないか、無効な値が指定されていると、 `url` 入力欄には最大文字数が設定されません。この値は `minlength` の値以上である必要もあります。 -

フィールドの URL の長さが UTF-16 コード単位で maxlength の長さを超えていると、その入力欄は制約検証に失敗します。制約検証はユーザーが値を変更した場合にのみ適用されます。

+フィールドの URL の長さが UTF-16 コード単位で `maxlength` の長さを超えていると、その入力欄は[制約検証](/ja/docs/Web/Guide/HTML/HTML5/Constraint_validation)に失敗します。制約検証はユーザーが値を変更した場合にのみ適用されます。

{{htmlattrdef("minlength")}}

-

ユーザーが url 入力欄に入力することができる (UTF-16 コード単位での) 最小文字数です。これは非負の整数値で、 maxlength で指定された値以下である必要があります。 minlength が指定されていないか、無効な値が指定されていると、 url 入力欄には最小文字数が設定されません。

+ユーザーが `url` 入力欄に入力することができる (UTF-16 コード単位での) 最小文字数です。これは非負の整数値で、 `maxlength` で指定された値以下である必要があります。 `minlength` が指定されていないか、無効な値が指定されていると、 `url` 入力欄には最小文字数が設定されません。 -

入力欄の URL の長さが UTF-16 コード単位で minlength の長さよりも短いと、その入力欄は制約検証に失敗します。制約検証はユーザーが値を変更した場合にのみ適用されます。

+入力欄の URL の長さが UTF-16 コード単位で `minlength` の長さよりも短いと、その入力欄は[制約検証](/ja/docs/Web/Guide/HTML/HTML5/Constraint_validation)に失敗します。制約検証はユーザーが値を変更した場合にのみ適用されます。

{{htmlattrdef("pattern")}}

-

{{page("/ja/docs/Web/HTML/Element/input/text", "pattern-include")}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "pattern-include")}} -

詳細と例については{{anch("Pattern validation", "パターン検証")}}の節を参照してください。

+詳細と例については{{anch("Pattern validation", "パターン検証")}}の節を参照してください。 -

{{page("/ja/docs/Web/HTML/Element/input/text", "placeholder", 0, 1, 2)}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "placeholder", 0, 1, 2)}} -

{{page("/ja/docs/Web/HTML/Element/input/text", "readonly", 0, 1, 2)}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "readonly", 0, 1, 2)}} -

{{page("/ja/docs/Web/HTML/Element/input/text", "size", 0, 1, 2)}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "size", 0, 1, 2)}} -

{{page("/ja/docs/Web/HTML/Element/input/text", "spellcheck", 0, 1, 2)}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "spellcheck", 0, 1, 2)}}

標準外の属性

-

ブラウザーによっては、以下の標準外の属性が利用できます。一般的な規則として、できれば使用することを避けてください。

+ブラウザーによっては、以下の標準外の属性が利用できます。一般的な規則として、できれば使用することを避けてください。
{{anch("list")}}`{{anch("list")}}` オプションで自動補完の定義済みの選択肢を含む <datalist> 要素の id
{{anch("maxlength")}}`{{anch("maxlength")}}` 入力欄が受け付ける最大文字数
{{anch("minlength")}}`{{anch("minlength")}}` 入力欄が取りうる、妥当と判断される最小文字列長
{{anch("pattern")}}`{{anch("pattern")}}` 妥当と判断されるために、入力欄の内容が一致する必要がある正規表現
{{anch("placeholder")}}`{{anch("placeholder")}}` 空欄の時に入力欄に表示される入力例の値
{{anch("readonly")}}`{{anch("readonly")}}` 入力欄の内容を読み取り専用にするかどうかを示す論理属性
{{anch("size")}}`{{anch("size")}}` 入力欄の長さを何文字分にするかを表す数値
{{anch("spellcheck")}}`{{anch("spellcheck")}}` 入力欄でスペルチェックを有効にするかどうか、既定のスペルチェック構成を利用するかを制御する
@@ -153,96 +153,96 @@ translation_of: Web/HTML/Element/input/url - - + + - +
{{anch("autocorrect")}}オートコレクトを行うかどうかを on または off で示します。 Safari のみ。`{{anch("autocorrect")}}`オートコレクトを行うかどうかを `on` または `off` で示します。 Safari のみ。
{{anch("mozactionhint")}}`{{anch("mozactionhint")}}` 入力欄を編集している間、ユーザーが Enter または Return キーを押したときに実行されるアクションを示す文字列です。これは仮想キーボードのキーに適切なラベルを特定するために使用します。 Android 版 Firefox for のみ。
-

{{page("/ja/docs/Web/HTML/Element/input/text", "autocorrect", 0, 1, 2)}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "autocorrect", 0, 1, 2)}} -

{{page("/ja/docs/Web/HTML/Element/input/text", "mozactionhint", 0, 1, 2)}}

+{{page("/ja/docs/Web/HTML/Element/input/text", "mozactionhint", 0, 1, 2)}}

URL 入力欄の使用

-

When you create a URL input with the proper type value, url, you get automatic validation that the entered text is at least in the correct form to potentially be a legitimate URL. This can help avoid cases in which the user mis-types their web site's address, or provides an invalid one.

+When you create a URL input with the proper `type` value, `url`, you get automatic validation that the entered text is at least in the correct form to potentially be a legitimate URL. This can help avoid cases in which the user mis-types their web site's address, or provides an invalid one. -

It's important, however, to note that this is not enough to ensure that the specified text is a URL which actually exists, corresponds to the user of the site, or is acceptable in any other way. It simply ensures that the value of the field is properly formatted to be a URL.

+It's important, however, to note that this is not enough to ensure that the specified text is a URL which actually exists, corresponds to the user of the site, or is acceptable in any other way. It simply ensures that the value of the field is properly formatted to be a URL.
-

: ユーザーが HTML をその場面の裏でいじることができることを意識しておくことは極めて重要です。ですから、安全を目的として、サイトでクライアント側の値検証機能のみを使用してはいけません。何らかのセキュリティ上の問題を含む可能性がある値が提供されるトランザクションの場合は、いずれもサーバー側で値検証を行う必要があります

+: ユーザーが HTML をその場面の裏でいじることができることを意識しておくことは極めて重要です。ですから、安全を目的として、サイトでクライアント側の値検証機能のみを使用してはいけません。何らかのセキュリティ上の問題を含む可能性がある値が提供されるトランザクションの場合は、いずれもサーバー側で値検証を行う必要があります

A simple URL input

-

Currently, all browsers which implement this element implement it as a standard text input field with basic validation features. In its most basic form, a URL input can be implemented like this:

+Currently, all browsers which implement this element implement it as a standard text input field with basic validation features. In its most basic form, a URL input can be implemented like this:
<input id="myURL" name="myURL" type="url">
-

{{ EmbedLiveSample('A_simple_URL_input', 600, 40) }}

+{{ EmbedLiveSample('A_simple_URL_input', 600, 40) }} -

Notice that it's considered valid when empty and when a single validly-formatted URL address is entered, but is otherwise not considered valid. By adding the {{htmlattrxref("required", "input")}} attribute, only properly-formed URLs are allowed; the input is no longer considered valid when empty.

+Notice that it's considered valid when empty and when a single validly-formatted URL address is entered, but is otherwise not considered valid. By adding the {{htmlattrxref("required", "input")}} attribute, only properly-formed URLs are allowed; the input is no longer considered valid when empty. -

There is nothing magical going on here. Submitting this form would cause the following data to be sent to the server: myURL=http%3A%2F%2Fwww.example.com. Note how characters are escaped as necessary.

+There is nothing magical going on here. Submitting this form would cause the following data to be sent to the server: `myURL=http%3A%2F%2Fwww.example.com`. Note how characters are escaped as necessary.

Placeholders

-

Sometimes it's helpful to offer an in-context hint as to what form the input data should take. This can be especially important if the page design doesn't offer descriptive labels for each {{HTMLElement("input")}}. This is where placeholders come in. A placeholder is a value that demonstrates the form the value should take by presenting an example of a valid value, which is displayed inside the edit box when the element's value is "". Once data is entered into the box, the placeholder disappears; if the box is emptied, the placeholder reappears.

+Sometimes it's helpful to offer an in-context hint as to what form the input data should take. This can be especially important if the page design doesn't offer descriptive labels for each {{HTMLElement("input")}}. This is where placeholders come in. A placeholder is a value that demonstrates the form the `value` should take by presenting an example of a valid value, which is displayed inside the edit box when the element's `value` is "". Once data is entered into the box, the placeholder disappears; if the box is emptied, the placeholder reappears. -

Here, we have a url input with the placeholder http://www.example.com. Note how the placeholder disappears and reappears as you manipulate the contents of the edit field.

+Here, we have a `url` input with the placeholder `http://www.example.com`. Note how the placeholder disappears and reappears as you manipulate the contents of the edit field.
<input id="myURL" name="myURL" type="url"
        placeholder="http://www.example.com">
-

{{ EmbedLiveSample('Placeholders', 600, 40) }}

+{{ EmbedLiveSample('Placeholders', 600, 40) }}

Controlling the input size

-

You can control not only the physical length of the input box, but also the minimum and maximum lengths allowed for the input text itself.

+You can control not only the physical length of the input box, but also the minimum and maximum lengths allowed for the input text itself.

Physical input element size

-

The physical size of the input box can be controlled using the {{htmlattrxref("size", "input")}} attribute. With it, you can specify the number of characters the input box can display at a time. In this example, for instance, the url edit box is 30 characters wide:

+The physical size of the input box can be controlled using the {{htmlattrxref("size", "input")}} attribute. With it, you can specify the number of characters the input box can display at a time. In this example, for instance, the `url` edit box is 30 characters wide:
<input id="myURL" name="myURL" type="url"
        size="30">
-

{{ EmbedLiveSample('Physical_input_element_size', 600, 40) }}

+{{ EmbedLiveSample('Physical_input_element_size', 600, 40) }}

Element value length

-

The size is separate from the length limitation on the entered URL itself. You can specify a minimum length, in characters, for the entered URL using the {{htmlattrxref("minlength", "input")}} attribute; similarly, use {{htmlattrxref("maxlength", "input")}} to set the maximum length of the entered URL. If maxLength exceeds size, the input box's contents will scroll as needed to show the current selection or insertion point as the content is manipulated.

+The `size` is separate from the length limitation on the entered URL itself. You can specify a minimum length, in characters, for the entered URL using the {{htmlattrxref("minlength", "input")}} attribute; similarly, use {{htmlattrxref("maxlength", "input")}} to set the maximum length of the entered URL. If `maxLength` exceeds `size`, the input box's contents will scroll as needed to show the current selection or insertion point as the content is manipulated. -

The example below creates a 30-character wide URL address entry box, requiring that the contents be no shorter than 10 characters and no longer than 80 characters.

+The example below creates a 30-character wide URL address entry box, requiring that the contents be no shorter than 10 characters and no longer than 80 characters.
<input id="myURL" name="myURL" type="url"
        size="30" minlength="10" maxlength="80">
 
-

{{EmbedLiveSample("Element_value_length", 600, 40) }}

+{{EmbedLiveSample("Element_value_length", 600, 40) }}
-

Note: These attributes also affect validation; a value shorter or longer than the specified minimum/maximum lengths will be classified as invalid; in addition most browsers will simply refuse to let the user enter a value longer than the specified maximum length.

+Note: These attributes also affect validation; a value shorter or longer than the specified minimum/maximum lengths will be classified as invalid; in addition most browsers will simply refuse to let the user enter a value longer than the specified maximum length.

Providing default options

-

As always, you can provide a default value for a url input box by setting its {{htmlattrxref("value", "input")}} attribute:

+As always, you can provide a default value for a `url` input box by setting its {{htmlattrxref("value", "input")}} attribute:
<input id="myURL" name="myURL" type="url"
        value="http://www.example.com">
-

{{EmbedLiveSample("Default_value", 600, 40)}}

+{{EmbedLiveSample("Default_value", 600, 40)}}

Offering suggested values

-

Taking it a step farther, you can provide a list of default options from which the user can select by specifying the {{htmlattrxref("list", "input")}} attribute. This doesn't limit the user to those options, but does allow them to select commonly-used URLs more quickly. This also offers hints to {{htmlattrxref("autocomplete", "input")}}. The list attribute specifies the ID of a {{HTMLElement("datalist")}}, which in turn contains one {{HTMLElement("option")}} element per suggested value; each option's value is the corresponding suggested value for the URL entry box.

+Taking it a step farther, you can provide a list of default options from which the user can select by specifying the {{htmlattrxref("list", "input")}} attribute. This doesn't limit the user to those options, but does allow them to select commonly-used URLs more quickly. This also offers hints to {{htmlattrxref("autocomplete", "input")}}. The `list` attribute specifies the ID of a {{HTMLElement("datalist")}}, which in turn contains one {{HTMLElement("option")}} element per suggested value; each `option`'s `value` is the corresponding suggested value for the URL entry box.
<input id="myURL" name="myURL" type="url"
        list="defaultURLs">
@@ -255,13 +255,13 @@ translation_of: Web/HTML/Element/input/url
   <option value="http://w3.org/">
 </datalist>
-

{{EmbedLiveSample("Offering_suggested_values", 600, 40)}}

+{{EmbedLiveSample("Offering_suggested_values", 600, 40)}} -

With the {{HTMLElement("datalist")}} element and its {{HTMLElement("option")}}s in place, the browser will offer the specified values as potential values for the URL; this is typically presented as a popup or drop-down menu containing the suggestions. While the specific user experience may vary from one browser to another, typically clicking in the edit box presents a drop-down of the suggested URLs. Then, as the user types, the list is adjusted to show only matching values. Each typed character narrows down the list until the user makes a selection or types a custom value.

+With the {{HTMLElement("datalist")}} element and its {{HTMLElement("option")}}s in place, the browser will offer the specified values as potential values for the URL; this is typically presented as a popup or drop-down menu containing the suggestions. While the specific user experience may vary from one browser to another, typically clicking in the edit box presents a drop-down of the suggested URLs. Then, as the user types, the list is adjusted to show only matching values. Each typed character narrows down the list until the user makes a selection or types a custom value.

Using labels for suggested values

-

You can opt to include the {{htmlattrxref("label", "option")}} attribute on one or all of your <option> elements to provide textual labels. Some browsers may display only the labels, while others may display both the label and the URL.

+You can opt to include the {{htmlattrxref("label", "option")}} attribute on one or all of your `<option>` elements to provide textual labels. Some browsers may display only the labels, while others may display both the label and the URL.
<input id="myURL" name="myURL" type="url"
        list="defaultURLs">
@@ -274,25 +274,25 @@ translation_of: Web/HTML/Element/input/url
   <option value="http://w3.org/" label="W3C">
 </datalist>
-

{{EmbedLiveSample("Using_labels_for_suggested_values", 600, 40)}}

+{{EmbedLiveSample("Using_labels_for_suggested_values", 600, 40)}}

Validation

-

There are two levels of content validation available for url inputs. First, there's the standard level of validation offered to all {{HTMLElement("input")}}s, which automatically ensures that the contents meet the requirements to be a valid URL. But there's also the option to add additional filtering to ensure that your own specialized needs are met, if you have any.

+There are two levels of content validation available for `url` inputs. First, there's the standard level of validation offered to all {{HTMLElement("input")}}s, which automatically ensures that the contents meet the requirements to be a valid URL. But there's also the option to add additional filtering to ensure that your own specialized needs are met, if you have any.
-

Important: HTML form validation is not a substitute for scripts that ensure that the entered data is in the proper format. It's far too easy for someone to make adjustments to the HTML that allow them to bypass the validation, or to remove it entirely. It's also possible for someone to simply bypass your HTML entirely and submit the data directly to your server. If your server-side code fails to validate the data it receives, disaster could strike when improperly-formatted data (or data which is too large, is of the wrong type, and so forth) is entered into your database.

+Important: HTML form validation is not a substitute for scripts that ensure that the entered data is in the proper format. It's far too easy for someone to make adjustments to the HTML that allow them to bypass the validation, or to remove it entirely. It's also possible for someone to simply bypass your HTML entirely and submit the data directly to your server. If your server-side code fails to validate the data it receives, disaster could strike when improperly-formatted data (or data which is too large, is of the wrong type, and so forth) is entered into your database.

Basic validation

-

Browsers that support the url input type automatically provide validation to ensure that only text that matches the standard format for URLs is entered into the input box.

+Browsers that support the `url` input type automatically provide validation to ensure that only text that matches the standard format for URLs is entered into the input box. -

The syntax of a URL is fairly intricate. It's defined by WHATWG's URL Living Standard and is described for newcomers in our article What is a URL?

+The syntax of a URL is fairly intricate. It's defined by WHATWG's [URL Living Standard](https://url.spec.whatwg.org/) and is described for newcomers in our article [What is a URL?](/ja/docs/Learn/Common_questions/What_is_a_URL)

Making a URL required

-

As mentioned earlier, to make a URL entry required before the form can be submitted (you can't leave the field blank), you just need to include the {{htmlattrxref("required", "input")}} attribute on the input.

+As mentioned earlier, to make a URL entry required before the form can be submitted (you can't leave the field blank), you just need to include the {{htmlattrxref("required", "input")}} attribute on the input.
<form>
@@ -301,17 +301,17 @@ translation_of: Web/HTML/Element/input/url
 </form>
-

{{EmbedLiveSample("Making_a_URL_required", 600, 40)}}

+{{EmbedLiveSample("Making_a_URL_required", 600, 40)}} -

Try submitting the above form with no value entered to see what happens.

+Try submitting the above form with no value entered to see what happens.

パターンによる値検証

-

If you need the entered URL to be restricted further than just "any string that looks like a URL," you can use the {{htmlattrxref("pattern", "input")}} attribute to specify a {{Glossary("regular expression")}} the value must match for the value to be valid.

+If you need the entered URL to be restricted further than just "any string that looks like a URL," you can use the {{htmlattrxref("pattern", "input")}} attribute to specify a {{Glossary("regular expression")}} the value must match for the value to be valid. -

For example, let's say you're building a support page for employees of Myco, Inc. which will let them contact their IT department for help if one of their pages has a problem. In our simplified form, the user needs to enter the URL of the page that has a problem, and a message describing what is wrong. But we want the URL to only successfully validate if the entered URL is in a Myco domain.

+For example, let's say you're building a support page for employees of Myco, Inc. which will let them contact their IT department for help if one of their pages has a problem. In our simplified form, the user needs to enter the URL of the page that has a problem, and a message describing what is wrong. But we want the URL to only successfully validate if the entered URL is in a Myco domain. -

Since inputs of type url validate against both the standard URL validation and the specified {{htmlattrxref("pattern", "input")}}, you can implement this easily. Let's see how:

+Since inputs of type `url` validate against both the standard URL validation and the specified {{htmlattrxref("pattern", "input")}}, you can implement this easily. Let's see how: