window.escape

  • Revision slug: DOM/window.escape
  • Revision title: window.escape
  • Revision id: 69910
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 8 words added

Revision Content

{{ DomRef() }}

Summary

Encodes a string, replacing certain characters with a hexadecimal escape sequence.

Syntax

escaped = escape(regular);
  • escaped is the encoded string.
  • regular is a regular string.

Example

alert(escape("http://www.cnn.com")); // displays: http%3A//www.cnn.com

Notes

The escape() method converts special characters (any characters that are not regular text or numbers) into hexadecimal characters, which is especially necessary for setting the values of cookies. Also useful when passing name=value pairs in the URL of a GET request, or an AJAX GET/POST request.

See also {{ domxref("window.unescape()") }}, encodeURIComponent().

Specification

{{ DOM0() }} Mentioned in a non-normative section of ECMA-262.

{{ languages( { "ja": "ja/DOM/window.escape" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>Encodes a string, replacing certain characters with a hexadecimal escape sequence.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval"><em>escaped</em> = escape(<em>regular</em>);
</pre>
<ul> <li><code>escaped</code> is the encoded string.</li> <li><code>regular</code> is a regular string.</li>
</ul>
<h3 id="Example" name="Example">Example</h3>
<pre class="eval">alert(escape("<span class="nowiki">http://www.cnn.com</span>")); // displays: http%3A//www.cnn.com
</pre>
<h3 id="Notes" name="Notes">Notes</h3>
<p>The <code>escape()</code> method converts special characters (any characters that are not regular text or numbers) into hexadecimal characters, which is especially necessary for setting the values of cookies. Also useful when passing <em>name=value</em> pairs in the URL of a GET request, or an AJAX GET/POST request.</p>
<p>See also {{ domxref("window.unescape()") }}, <code><a href="/en/JavaScript/Reference/Global_Objects/encodeURIComponent" title="DekiScript Code Snippets">encodeURIComponent()</a></code>.</p><h3 id="Specification" name="Specification">Specification</h3>
<p>{{ DOM0() }} Mentioned in a non-normative section of ECMA-262.</p> <p>{{ languages( { "ja": "ja/DOM/window.escape" } ) }}</p>
Revert to this revision