1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JavaScript encodeURI()関数:URL全体をエンコードする場合

1
Posted at

概念と使用方法

encodeURI()関数はURL構造を定義する一部の特殊文字を除いてURLをエンコードします。 この関数は主にURL全体の文字列をエンコードする際に使用されます。

基本の例

const uri = "https://www.example.com/?x=サンプル値";
const encoded = encodeURI(uri);

console.log(encoded);
// 出力: "https://www.example.com/?x=%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E5%80%A4"

返り値

指定された文字列をURIとしてエンコードした新しい文字列を返します。

const uri = "https://example.com/search?query=Hello, world!&page=1";
const encodedUri = encodeURI(uri);

console.log(encodedUri);
// 出力: "https://example.com/search?query=Hello%2C%20world!&page=1"

この例では、encodeURI()関数はuri変数に格納されたURIをエンコードします。エンコードされない特殊文字は、:、/、?、&、=、!などです。

参考資料

codingEverybody - JavaScript encodeURI()関数:URL全体をエンコードする場合
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?