escape() and unescape()
escape() と unescape() は文字列をエンコード・デコードするレガシー関数です。encodeURIComponent() / decodeURIComponent() の使用が推奨されます。
概要
escape() と unescape() は文字列をエンコード・デコードするレガシー関数です。encodeURIComponent() / decodeURIComponent() の使用が推奨されます。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
escape 非推奨 | 1 | 12 | 1 | 1 | 18 | 1 |
| その他 | ||||||
| unescape() 関数は、16 進エスケープシーケンスをそれらが表す文字に置き換えた新しい文字列を計算します。エスケープシーケンスは、 escape() のような関数によって導入される場合があります。 | 1 | 12 | 1 | 1 | 18 | 1 |
基本構文
JAVASCRIPT
// escape() and unescape() example
// See MDN Web Docs for details ライブデモ
Encode with escape and encodeURIComponent
Compare the legacy functions with modern URL-safe encoding.
JavaScript
出力
「実行」ボタンを押してください
Decode encoded text
Restore the original string from an escaped sequence.
JavaScript
出力
「実行」ボタンを押してください
Handle non-ASCII characters
See why escape/unescape are legacy APIs for Unicode text.
JavaScript
出力
「実行」ボタンを押してください
実務での使いどころ
-
escape() and unescape() の活用
escape() と unescape()(非推奨)。文字列のエンコード・デコード。encodeURIComponent を代替に使用。
注意点
- 一部のブラウザでのみ対応。使用前にブラウザサポートを確認すること。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。
参考リンク
Powered by web-features