window.escape

  • Revision slug: Web/API/window.escape
  • Revision title: window.escape
  • Revision id: 432511
  • Created:
  • Creator: Brettz9
  • Is current revision? No
  • Comment

Revision Content

{{DomRef}}

Summary

Encodes a string, replacing all characters except for ASCII digits, lower and upper case letters, and the 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.

Revision Source

<div>
  {{DomRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Encodes a string, replacing all characters except for ASCII digits, lower and upper case letters, and the characters * + - . / @ _ with a hexadecimal escape sequence.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<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>
<h2 id="Example" name="Example">Example</h2>
<pre class="brush:js">
alert( escape("http://www.cnn.com") ); // displays: http%3A//www.cnn.com
</pre>
<h2 id="Notes" name="Notes">Notes</h2>
<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-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent" title="DekiScript Code Snippets">encodeURIComponent()</a></code>.</p>
<h2 id="Specification" name="Specification">Specification</h2>
<p>{{DOM0}} Mentioned in a non-normative section of ECMA-262.</p>
Revert to this revision